future

package module
v0.0.0-...-18f5bce Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: MIT Imports: 5 Imported by: 0

README

Quality Docs License
CodeFactor GoDocs License

Try to run BenchmarkFuture()

Why?

  • if you don't want repeated casting of interface{} to your desired types (in args and results)
  • if you don't want repeated initialization of your channels+goroutines just to make a common pattern
  • if you wanted control back, having your desired parameters in your resolv or reject functions (when using a 3rd party lib)

Content

  • func Future( anyfunc(resolvfunc, rejectfunc) ) (*Promise)
  • func FutureDeferred( anyfunc(resolvfunc, rejectfunc) ) (exec func(bAsync bool), *Promise)
  • func Race(...*Promise) (*Promise)
  • Promise
    • Then(resolvedfunc, rejectedfunc) (*Promise)
    • OnSuccess(resolvedfunc) (*Promise)
    • OnFail(rejectedfunc) (*Promise)
    • Wait()
    • SetCatch( recoverfn func(...interface{}) )
    • SetFinally( func(state, ...interface{}) ) // state: {resolved, rejected, recovered}

:: resolvedfunc and rejectedfunc can have any function signature

Example

	exec, q := FutureDeferred( func(resolvFn, rejectFn){
		// ... do something
		resolvFn("success")
	})
	
	q.OnSuccess(fn1, fn2, fn3)
	q.OnFail(fn1, fn2)
	
	q.SetCatch( onRecoverFn )
	q.SetFinally( onDone )
	
	bAsync := false
	exec(bAsync)

Documentation

Overview

Notes: https://promisesaplus.com/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FinalState

type FinalState int
const (
	FinalUnknown FinalState = iota
	FinalResolved
	FinalRejected
	FinalRecovered
)

type Promise

type Promise struct {
	// contains filtered or unexported fields
}

func Future

func Future(fn interface{}) (q *Promise)

func FutureDeferred

func FutureDeferred(fn interface{}) (exec func(bAsync bool), q *Promise)

func Race

func Race(qs ...*Promise) (q *Promise)

returns first promise to finish or rejected

func (*Promise) OnFail

func (this *Promise) OnFail(rejectedFns ...interface{}) (q *Promise)

func (*Promise) OnSuccess

func (this *Promise) OnSuccess(fulfilledFns ...interface{}) (q *Promise)

func (*Promise) SetCatch

func (this *Promise) SetCatch(recoverFn func(error, interface{}))

func (*Promise) SetFinally

func (this *Promise) SetFinally(finallyFn func(FinalState, ...interface{}))

func (*Promise) Then

func (this *Promise) Then(fulfilledFn, rejectedFn interface{}) (q *Promise)

func (*Promise) Wait

func (this *Promise) Wait()

Jump to

Keyboard shortcuts

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