|
| 1 | +Vardius - gollback |
| 2 | +================ |
| 3 | +[](https://travis-ci.org/vardius/gollback) |
| 4 | +[](https://goreportcard.com/report/github.com/vardius/gollback) |
| 5 | +[](https://codecov.io/gh/vardius/gollback) |
| 6 | +[](http://godoc.org/github.com/vardius/gollback) |
| 7 | +[](https://github.com/vardius/gollback/blob/master/LICENSE.md) |
| 8 | + |
| 9 | +gollback - Go asynchronous function simple utilities, for managing execution of closure, callbacks. |
| 10 | + |
| 11 | +ABOUT |
| 12 | +================================================== |
| 13 | +Contributors: |
| 14 | + |
| 15 | +* [Rafał Lorenz](http://rafallorenz.com) |
| 16 | + |
| 17 | +Want to contribute ? Feel free to send pull requests! |
| 18 | + |
| 19 | +Have problems, bugs, feature ideas? |
| 20 | +We are using the github [issue tracker](https://github.com/vardius/gollback/issues) to manage them. |
| 21 | + |
| 22 | +HOW TO USE |
| 23 | +================================================== |
| 24 | + |
| 25 | +1. [GoDoc](http://godoc.org/github.com/vardius/gollback) |
| 26 | + |
| 27 | +## Benchmark |
| 28 | +**CPU: 3,3 GHz Intel Core i7** |
| 29 | + |
| 30 | +**RAM: 16 GB 2133 MHz LPDDR3** |
| 31 | + |
| 32 | +```bash |
| 33 | +➜ gollback git:(master) ✗ go test -bench=. -cpu=4 -benchmem |
| 34 | +goos: darwin |
| 35 | +goarch: amd64 |
| 36 | +pkg: github.com/vardius/gollback |
| 37 | +BenchmarkRace-4 5000000 240 ns/op 0 B/op 0 allocs/op |
| 38 | +BenchmarkAll-4 1000000 2387 ns/op 464 B/op 2 allocs/op |
| 39 | +PASS |
| 40 | +ok github.com/vardius/gollback 10.572s |
| 41 | +``` |
| 42 | + |
| 43 | +## All example |
| 44 | +```go |
| 45 | +package main |
| 46 | + |
| 47 | +import ( |
| 48 | + "context" |
| 49 | + "errors" |
| 50 | + "fmt" |
| 51 | + "time" |
| 52 | + |
| 53 | + "github.com/vardius/gollback" |
| 54 | +) |
| 55 | + |
| 56 | +func main() { |
| 57 | + g := gollback.New(context.Background()) |
| 58 | + |
| 59 | + rs, errs := g.Race( |
| 60 | + func(ctx context.Context) (interface{}, error) { |
| 61 | + time.Sleep(3 * time.Second) |
| 62 | + return 1, nil |
| 63 | + }, |
| 64 | + func(ctx context.Context) (interface{}, error) { |
| 65 | + return nil, errors.New("failed") |
| 66 | + }, |
| 67 | + func(ctx context.Context) (interface{}, error) { |
| 68 | + return 3, nil |
| 69 | + }, |
| 70 | + ) |
| 71 | + |
| 72 | + fmt.Println(rs) |
| 73 | + fmt.Println(errs) |
| 74 | + // Output: |
| 75 | + // [1 <nil> 3] |
| 76 | + // [<nil> failed <nil>] |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Race example |
| 81 | +```go |
| 82 | +package main |
| 83 | + |
| 84 | +import ( |
| 85 | + "context" |
| 86 | + "errors" |
| 87 | + "fmt" |
| 88 | + "time" |
| 89 | + |
| 90 | + "github.com/vardius/gollback" |
| 91 | +) |
| 92 | + |
| 93 | +func main() { |
| 94 | + g := gollback.New(context.Background()) |
| 95 | + |
| 96 | + r, err := g.Race( |
| 97 | + func(ctx context.Context) (interface{}, error) { |
| 98 | + time.Sleep(3 * time.Second) |
| 99 | + return 1, nil |
| 100 | + }, |
| 101 | + func(ctx context.Context) (interface{}, error) { |
| 102 | + return nil, errors.New("failed") |
| 103 | + }, |
| 104 | + func(ctx context.Context) (interface{}, error) { |
| 105 | + return 3, nil |
| 106 | + }, |
| 107 | + ) |
| 108 | + |
| 109 | + fmt.Println(r) |
| 110 | + fmt.Println(err) |
| 111 | + // Output: |
| 112 | + // 3 |
| 113 | + // <nil> |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +License |
| 118 | +------- |
| 119 | + |
| 120 | +This package is released under the MIT license. See the complete license in the package: |
| 121 | + |
| 122 | +[LICENSE](LICENSE.md) |
0 commit comments