Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vardius/gollback
Go asynchronous simple function utilities, for managing execution of closures and callbacks
https://github.com/vardius/gollback
callback cancel closure future golang goroutine promise race retry timeout
Last synced: about 2 months ago
JSON representation
Go asynchronous simple function utilities, for managing execution of closures and callbacks
- Host: GitHub
- URL: https://github.com/vardius/gollback
- Owner: vardius
- License: mit
- Created: 2019-05-11T05:56:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-16T21:51:46.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T06:09:02.240Z (2 months ago)
- Topics: callback, cancel, closure, future, golang, goroutine, promise, race, retry, timeout
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 124
- Watchers: 1
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-go - gollback - asynchronous simple function utilities, for managing execution of closures and callbacks. (Goroutines / Search and Analytic Databases)
- awesome-go-extra - gollback - 05-11T05:56:37Z|2022-02-17T08:48:36Z| (Goroutines / Advanced Console UIs)
README
βοΈ gollback
================
[![Build Status](https://travis-ci.org/vardius/gollback.svg?branch=master)](https://travis-ci.org/vardius/gollback)
[![Go Report Card](https://goreportcard.com/badge/github.com/vardius/gollback)](https://goreportcard.com/report/github.com/vardius/gollback)
[![codecov](https://codecov.io/gh/vardius/gollback/branch/master/graph/badge.svg)](https://codecov.io/gh/vardius/gollback)
[![](https://godoc.org/github.com/vardius/gollback?status.svg)](https://pkg.go.dev/github.com/vardius/gollback)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/vardius/gollback/blob/master/LICENSE.md)gollback - Go asynchronous simple function utilities, for managing execution of closures and callbacks
π ABOUT
==================================================
Contributors:* [RafaΕ Lorenz](http://rafallorenz.com)
Want to contribute ? Feel free to send pull requests!
Have problems, bugs, feature ideas?
We are using the github [issue tracker](https://github.com/vardius/gollback/issues) to manage them.## π Documentation
For __examples__ **visit [godoc#pkg-examples](http://godoc.org/github.com/vardius/gollback#pkg-examples)**
For **GoDoc** reference, **visit [pkg.go.dev](https://pkg.go.dev/github.com/vardius/gollback)**
π HOW TO USE
==================================================## π Benchmark
**CPU: 3,3 GHz Intel Core i7****RAM: 16 GB 2133 MHz LPDDR3**
```bash
β gollback git:(master) β go test -bench=. -cpu=4 -benchmem
goos: darwin
goarch: amd64
pkg: github.com/vardius/gollback
BenchmarkRace-4 566022 2608 ns/op 663 B/op 5 allocs/op
BenchmarkAll-4 5052489 241 ns/op 42 B/op 1 allocs/op
BenchmarkRetry-4 206430384 5.93 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/vardius/gollback 31.741s
```## Race
> Race method returns a response as soon as one of the callbacks in an iterable resolves with the value that is not an error, otherwise last error is returne
```go
package mainimport (
"context"
"errors"
"fmt"
"time""github.com/vardius/gollback"
)func main() {
r, err := gollback.Race(
context.Background(),
func(ctx context.Context) (interface{}, error) {
time.Sleep(3 * time.Second)
return 1, nil
},
func(ctx context.Context) (interface{}, error) {
return nil, errors.New("failed")
},
func(ctx context.Context) (interface{}, error) {
return 3, nil
},
)
}
```## All
> All method returns when all of the callbacks passed as an iterable have finished, returned responses and errors are ordered according to callback order
```go
package mainimport (
"context"
"errors"
"fmt"
"time""github.com/vardius/gollback"
)func main() {
rs, errs := gollback.All(
context.Background(),
func(ctx context.Context) (interface{}, error) {
time.Sleep(3 * time.Second)
return 1, nil
},
func(ctx context.Context) (interface{}, error) {
return nil, errors.New("failed")
},
func(ctx context.Context) (interface{}, error) {
return 3, nil
},
)
}
```## Retry
> Retry method retries callback given amount of times until it executes without an error, when retries = 0 it will retry infinitely
```go
package mainimport (
"context"
"errors"
"fmt"
"time""github.com/vardius/gollback"
)func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()// Will retry infinitely until timeouts by context (after 5 seconds)
res, err := gollback.Retry(ctx, 0, func(ctx context.Context) (interface{}, error) {
return nil, errors.New("failed")
})// Will retry 5 times or will timeout by context (after 5 seconds)
res, err := gollback.Retry(ctx, 5, func(ctx context.Context) (interface{}, error) {
return nil, errors.New("failed")
})
}
```π [License](LICENSE.md)
-------This package is released under the MIT license. See the complete license in the package