github.com/influx6/npkg@v0.8.8/nchain/Readme.md (about) 1 FutureChain 2 --------------- 3 FutureChain implements a future-like inter-dependent pipeline using golang error group. 4 It allows usage of the power which the [Error Group](http://golang.org/x/sync/errgroup) package provides in safe conccurent 5 functions with returned error. 6 7 ## Install 8 9 ```go 10 go get github.com/influx6/npkg/nchain 11 ``` 12 13 ## Example 14 15 - Sequential concurrent executions where one future is depent on the completion of 16 another concurrent future operation. 17 18 ```go 19 chain := futurechain.NewFutureChain(context.Background(), func() error { 20 return nil 21 }).Go(func() error{ 22 // This will be executed with the chain function concurrently using 23 // goroutines. 24 return nil 25 }).When(func() error { 26 // First dependent sequentail concurrent chain. 27 return nil 28 }).Go(func() error { 29 // We be executed concurrently with the sequential concurrent chain 30 // returned by Chain.When(). 31 return nil 32 }) 33 34 chain.Wait() 35 ``` 36 37 - Deferred future chains 38 39 This are cases where you can create a future which may be passed around to different functions 40 which will be executed by another future not yet created or ready. 41 42 ```go 43 chain := futurechain.NewFutureChain(context.Background(), func() error { 44 // .... 45 return nil 46 }) 47 48 // Deferred chain can be created, if will not be executed until another 49 // chain triggers it based on whatever method you use to chain. 50 chain2 := futurechain.DeferredChain(context.Background(), func() error { 51 // .... 52 return nil 53 }) 54 55 // We want to trigger deffered chain regardless of error from first chain. 56 chain.ChainFuture(chain2) 57 58 chain2.Wait() 59 ```