All Projects → vardius → Gollback

vardius / Gollback

Licence: mit
Go asynchronous simple function utilities, for managing execution of closures and callbacks

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gollback

Promises
It's just another Promise library...
Stars: ✭ 43 (-21.82%)
Mutual labels:  promise, future
Retry
because you should never give up, at least not on the first try
Stars: ✭ 303 (+450.91%)
Mutual labels:  future, retry
run exclusive
⚡🔒 Wait queue for function execution 🔒 ⚡
Stars: ✭ 22 (-60%)
Mutual labels:  promise, callback
Routine
go routine control, abstraction of the Main and some useful Executors.如果你不会管理Goroutine的话,用它
Stars: ✭ 40 (-27.27%)
Mutual labels:  goroutine, retry
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+874.55%)
Mutual labels:  promise, future
retryx
Promise-based retry workflow library.
Stars: ✭ 21 (-61.82%)
Mutual labels:  promise, retry
Future
Streamlined Future<Value, Error> implementation
Stars: ✭ 291 (+429.09%)
Mutual labels:  promise, future
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (-40%)
Mutual labels:  promise, callback
Thunks
A small and magical composer for all JavaScript asynchronous.
Stars: ✭ 523 (+850.91%)
Mutual labels:  promise, callback
Replace In File
A simple utility to quickly replace contents in one or more files
Stars: ✭ 369 (+570.91%)
Mutual labels:  promise, callback
retrygroup
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.
Stars: ✭ 18 (-67.27%)
Mutual labels:  retry, goroutine
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (+1550.91%)
Mutual labels:  promise, future
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-63.64%)
Mutual labels:  promise, callback
redis-memolock
Redis MemoLock - Distributed Caching with Promises
Stars: ✭ 63 (+14.55%)
Mutual labels:  promise, future
lightflow
A tiny Promise-inspired control flow library for browser and Node.js.
Stars: ✭ 29 (-47.27%)
Mutual labels:  promise, callback
asynqro
Futures and thread pool for C++ (with optional Qt support)
Stars: ✭ 103 (+87.27%)
Mutual labels:  promise, future
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+89.09%)
Mutual labels:  promise, future
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+87.27%)
Mutual labels:  promise, callback
Fun Task
Abstraction for managing asynchronous code in JS
Stars: ✭ 363 (+560%)
Mutual labels:  promise, future
Minifuture
A monadic Future design pattern implementation in Swift
Stars: ✭ 16 (-70.91%)
Mutual labels:  promise, future

⚙️ gollback

Build Status Go Report Card codecov license

logo

gollback - Go asynchronous simple function utilities, for managing execution of closures and callbacks

📖 ABOUT

Contributors:

Want to contribute ? Feel free to send pull requests!

Have problems, bugs, feature ideas? We are using the github issue tracker to manage them.

📚 Documentation

For examples visit godoc#pkg-examples

For GoDoc reference, visit pkg.go.dev

🚏 HOW TO USE

🚅 Benchmark

CPU: 3,3 GHz Intel Core i7

RAM: 16 GB 2133 MHz LPDDR3

➜  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

package main

import (
	"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

package main

import (
	"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

package main

import (
	"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

This package is released under the MIT license. See the complete license in the package

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].