hands alternatives and similar packages
Based on the "Goroutines" category.
Alternatively, view hands alternatives based on common mentions on social networks and blogs.
-
Goflow
Simply way to control goroutines execution order based on dependencies -
async
A safe way to execute functions asynchronously, recovering them in case of panic. -
artifex
Simple in-memory job queue for Golang using worker-based dispatching. -
go-workers
Easily and safely run workers for large data processing pipelines. -
go-do-work
Dynamically resizable pools of goroutines which can queue an infinite number of jobs. -
semaphore
Semaphore pattern implementation with timeout of lock/unlock operations based on channel and context. -
gpool
manages a resizeable pool of context-aware goroutines to bound concurrency. -
neilotoole/errgroup
Drop-in alternative to sync/errgroup, limited to a pool of N worker goroutines. -
gollback
asynchronous simple function utilities, for managing execution of closures and callbacks. -
Hunch
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive. -
routine
go routine control with context, support: Main, Go, Pool and some useful Executors. -
goccm
Go Concurrency Manager package limits the number of goroutines that allowed to run concurrently. -
go-waitgroup
Like sync.WaitGroup with error handling and concurrency control. -
conexec
A concurrent toolkit to help execute funcs concurrently in an efficient and safe way.It supports specifying the overall timeout to avoid blocking and uses goroutine pool to improve efficiency. -
go-tools/multithreading
Manage a pool of goroutines using this lightweight library with a simple API. -
channelify
Transform your function to return channels for easy and powerful parallel processing. -
queue
Gives you a sync.WaitGroup like queue group accessibility. Helps you to throttle and limit goroutines, wait for the end of the all goroutines and much more. -
concurrency-limiter
Concurrency limiter with support for timeouts , dynamic priority and context cancellation of goroutines. -
oversight
Oversight is a complete implementation of the Erlang supervision trees.
Scout APM - Leading-edge performance monitoring starting at $39/month
Do you think we are missing an alternative of hands or a related project?
Popular Comparisons
README
Hands
“Dedicated to Brother Chang”
Hands is a process controller used to control the execution and return strategies of multiple goroutines.
Getting started
A simple example
n := 0
controller := hands.New()
controller.Do(func(ctx context.Context) error {
n++
return nil
})
err := controller.Run()
if err != nil {
// ...
}
fmt.Println(n)
// Output:
// 1
Use the Do
method to add a task, use the Run
method to start the task(s).
TaskOption
TaskOption
is used to set some metadata for the task.
func Priority(priority int32) TaskOption
Use the Priority
method to set a priority for a task. The higher the priority, the higher the execution order.
(hands.P()
is an alias for hands.Priority()
.)
controller := New()
controller.Do(func(ctx context.Context) error {
fmt.Println("3")
return nil
}, hands.P(1))
controller.Do(func(ctx context.Context) error {
fmt.Println("2")
return nil
}, hands.P(2))
controller.Do(func(ctx context.Context) error {
fmt.Println("1")
return nil
}, hands.P(3))
controller.Run()
// Output:
// 1
// 2
// 3
HandOption
HandOption is used to control the execution strategy of the task.
func Fastest() HandOption
Fastest()
: When a task is completed, return immediately.
n := 0
controller := hands.New()
controller.Do(func(ctx context.Context) error {
time.Sleep(time.Duration(10) * time.Millisecond)
n += 1
return nil
})
controller.Do(func(ctx context.Context) error {
n += 2
return nil
})
controller.Run(hands.Fastest())
fmt.Println(n)
// Output:
// 2
func Percentage(percentage float32) HandOption
When a certain percentage of tasks are executed, the results are returned.
n := 0
controller := hands.New()
controller.Do(func(ctx context.Context) error {
n++
return nil
})
controller.Do(func(ctx context.Context) error {
n++
return nil
})
controller.Do(func(ctx context.Context) error {
n++
return nil
})
controller.Do(func(ctx context.Context) error {
n++
return nil
})
controller.Run(hands.Percentage(0.5))
fmt.Println(n)
// Output:
// 2
func Between(l, r int32) HandOption
Between()
: Only execute tasks with a priority within the specified range.
n := 0
controller := hands.New()
controller.Do(func(ctx context.Context) error {
n += 1
return nil
}, hands.P(1))
controller.Do(func(ctx context.Context) error {
n += 2
return nil
}, hands.P(2))
controller.Do(func(ctx context.Context) error {
n += 3
return nil
}, hands.P(3))
controller.Do(func(ctx context.Context) error {
n += 4
return nil
}, hands.P(4))
controller.Run(hands.Between(2, 3))
fmt.Println(n)
// Output:
// 5
Note: If the use the controller.Run()
method, tasks outside the Between()
will not be executed, you can use the controller.RunAll()
method to allow other priority tasks to be executed asynchronously.
...
controller.RunAll(hands.Between(2, 3))
fmt.Println(n)
time.Sleep(time.Duration(10) * time.Millisecond)
fmt.Println(n)
// Output:
// 5
// 10
func In(in []int32) HandOption
In()
: Only execute tasks in the specified priority list.
n := 0
controller := hands.New()
controller.Do(func(ctx context.Context) error {
n += 1
return nil
}, hands.P(1))
controller.Do(func(ctx context.Context) error {
n += 2
return nil
}, hands.P(2))
controller.Do(func(ctx context.Context) error {
n += 3
return nil
}, hands.P(3))
controller.Do(func(ctx context.Context) error {
n += 4
return nil
}, hands.P(4))
controller.Run(hands.In([]int32{2, 4}))
fmt.Println(n)
// Output:
// 6
Yes, the controller.RunAll()
method can also be used here.
...
controller.RunAll(hands.In([]int32{2, 4}))
fmt.Println(n)
time.Sleep(time.Duration(10) * time.Millisecond)
fmt.Println(n)
// Output:
// 6
// 10
func WithContext(ctx context.Context) HandOption
Make the task use the specified context.
c, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
defer cancel()
controller := hands.New()
controller.Do(func(ctx context.Context) error {
time.Sleep(time.Duration(100) * time.Millisecond)
return nil
})
err := controller.Run(hands.WithContext(c))
fmt.Println(err.Error())
// Output:
// context deadline exceeded
Callback after all tasks have been executed
n := 0
controller := hands.New()
controller.Do(func(ctx context.Context) error {
time.Sleep(time.Duration(10) * time.Millisecond)
n++
return nil
})
controller.Do(func(ctx context.Context) error {
time.Sleep(time.Duration(10) * time.Millisecond)
n++
return nil
})
controller.Do(func(ctx context.Context) error {
n += 5
return nil
})
// Here.
controller.Done(func() {
// `True`
assert.Equal(t, n, 7)
})
controller.RunAll(Fastest())
// `True`
assert.Equal(t, n, 5)
time.Sleep(time.Duration(500) * time.Millisecond)
License
*Note that all licence references and agreements mentioned in the hands README section above
are relevant to that project's source code only.