Skip to content

noypi/future

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

golang futures / promise with any function signature you like.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages