promise

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 5 Imported by: 0

README

Go Promise

Go Report Card Build Status Go Reference

Promise / Future library for Go

Aim

This library provides a promise interface similar to JavaScript 's

Features

  • Generics (Type Parameters) support
  • Interface similar to JS 's
  • Cancellable promises
  • Time-out support
  • Promises which can be committed separately
  • Promise maps
  • Race functionality
  • Automatic panic recovery
  • Fluent interface / Chain API
  • No external dependency

To-Do

no to-do

Installation

go get github.com/abdullahpazarbasi/promise

Usage

examples

License

This library licensed under MIT License.

Documentation

Index

Constants

View Source
const (
	EventResolved event = iota
	EventRejected
	EventCanceled
	EventTimedOut
	EventEliminated
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Future

type Future[T any] interface {
	TimeOutLimit(timeOutLimit time.Duration) Future[T]
	OnResolved(onResolved func(T)) Future[T]
	OnRejected(onRejected func(error)) Future[T]
	OnCanceled(onCanceled func()) Future[T]
	OnTimedOut(onTimedOut func()) Future[T]
	Finally(finally func(event)) Future[T]
	Commit() Progress[T]
	Await() (T, error)
	// contains filtered or unexported methods
}

func New

func New[T any](async func() (T, error)) Future[T]

type FutureMap

type FutureMap[T any] interface {
	Commit() ProgressMap[T]
	Await() *map[interface{}]Output[T]
	Race() (key interface{}, pay T, err error)
	// contains filtered or unexported methods
}

func NewMap

func NewMap[T any](m map[interface{}]interface{}, timeOutLimit time.Duration) FutureMap[T]

type Output

type Output[T any] interface {
	Payload() T
	Error() error
	// contains filtered or unexported methods
}

type Progress

type Progress[T any] interface {
	Cancel()
	Await() (T, error)
	// contains filtered or unexported methods
}

type ProgressMap

type ProgressMap[T any] interface {
	Cancel()
	Await() *map[interface{}]Output[T]
	Race() (key interface{}, pay T, err error)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL