• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

βš™οΈ 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

More Repositories

1

go-api-boilerplate

Go Server/API boilerplate using best practices DDD CQRS ES gRPC
Go
924
star
2

message-bus

Go simple async message bus
JavaScript
247
star
3

gorouter

Go Server/API micro framework, HTTP request router, multiplexer, mux
Go
154
star
4

worker-pool

Go simple async worker pool
Go
87
star
5

peer-data

Library for files, media streaming/sharing using WebRTC
JavaScript
64
star
6

peer-cdn

Lightweight library providing peer to peer CDN functionality
JavaScript
61
star
7

progress-go

Go simple progress bar writing to output
Go
53
star
8

web-components-webpack-es6-boilerplate

Web Components project starter using ES6 and Webpack
JavaScript
44
star
9

pubsub

gRPC message-oriented middleware on top of message-bus, event ingestion and delivery system.
Go
41
star
10

react-webrtc-chat

React WebRTC chat
JavaScript
41
star
11

web-component

Lightweight library providing interface for building web components
JavaScript
39
star
12

webrtc-chat

Serverless chat application useing peer to peer WebRTC
JavaScript
29
star
13

react-peer-data

React wrapper for PeerData library for files, media streaming/sharing using WebRTC.
TypeScript
20
star
14

react-user-media

React wrapper for getUserMedia
TypeScript
19
star
15

shutdown

Simple go signals handler for performing graceful shutdown by executing callback function
Go
18
star
16

gocontainer

Simple Dependency Injection Container
Go
18
star
17

pushpull

gRPC message-oriented middleware on top of worker-pool, event ingestion and delivery system.
Go
10
star
18

peer-data-server

Signaling server, messaging service on Node using socket
JavaScript
10
star
19

invoice-bundle

Symfony invoice bundle
JavaScript
8
star
20

blockchain

Simple gRPC blockchain
Go
8
star
21

crud-bundle

Provides crud actions, crud bundle for Symfony
PHP
7
star
22

trace

Simple helper to trace the function calls, errors or logs reference
Go
7
star
23

list-bundle

Provides list builder, list view bundle for Symfony
PHP
4
star
24

golog

Go logger
Go
4
star
25

goquery

Go query builder for sql
Go
3
star
26

gocrud

Simple Go (Golang) CRUD provider
Go
3
star
27

angular-symfony-acl

ACL component for Angular Js based on symfony2 user roles
JavaScript
2
star
28

angular-gravatar

Angular gravatar component
JavaScript
2
star
29

ng2-search

Angular 2 search module
JavaScript
1
star
30

angular2-chat

Socket.io Chat with NodeJS and Angular2
JavaScript
1
star
31

ng2-pagination

Angular2 pagination module
TypeScript
1
star
32

user-bundle

Simple symfony doctrine user bundle
PHP
1
star
33

mean-todos

MEAN (MongoDB, ExpressJS, Angular2, NodeJS) Todo List application
TypeScript
1
star
34

angular-oauth2

Angular oauth2 provider
JavaScript
1
star
35

angular2-github

GitHub User Search - Angular2 + Webpack App
JavaScript
1
star
36

vardius.github.io

SCSS
1
star
37

angular2-spotify

Spotify - Angular2 + Webpack App
JavaScript
1
star
38

menu-bundle

Simple symfony menu builder
PHP
1
star
39

admin-bundle

Symfony admin bundle, CMS
JavaScript
1
star
40

lru-cache

A Least Recently Used (LRU) Cache organizes items in order of use, allowing you to quickly identify which item hasn't been used for the longest amount of time.
Go
1
star