nursery alternatives and similar packages
Based on the "Goroutines" category.
Alternatively, view nursery alternatives based on common mentions on social networks and blogs.
-
goworker
goworker is a Go-based background worker that runs 10 to 100,000* times faster than Ruby-based workers. -
pool
:speedboat: a limited consumer goroutine or unlimited goroutine pool for easier goroutine handling and cancellation -
go-workers
DISCONTINUED. ๐ท Library for safely running groups of workers concurrently or consecutively that require input and output through channels -
async
A safe way to execute functions asynchronously, recovering them in case of panic. It also provides an error stack aiming to facilitate fail causes discovery. -
gollback
Go 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. -
gpool
gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore. -
gowl
Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status. -
routine
go routine control, abstraction of the Main and some useful Executors.ๅฆๆไฝ ไธไผ็ฎก็Goroutine็่ฏ๏ผ็จๅฎ -
kyoo
Unlimited job queue for go, using a pool of concurrent workers processing the job queue entries -
execpool
A pool that spins up a given number of processes in advance and attaches stdin and stdout when needed. Very similar to FastCGI but works for any command. -
concurrency-limiter
Concurrency limiter with support for timeouts , dynamic priority and context cancellation of goroutines. -
conexec
A concurrent toolkit to help execute funcs concurrently in an efficient and safe way. It supports specifying the overall timeout to avoid blocking. -
queue
package queue gives you a queue group accessibility. Helps you to limit goroutines, wait for the end of the all goroutines and much more. -
hands
Hands is a process controller used to control the execution and return strategies of multiple goroutines. -
async-job
AsyncJob is an asynchronous queue job manager with light code, clear and speed. I hope so ! ๐ฌ
CodeRabbit: AI Code Reviews for Developers
Do you think we are missing an alternative of nursery or a related project?
README
nursery: structured concurrency in Go
RunConcurrently(
// Job 1
func(context.Context, chan error) {
time.Sleep(time.Millisecond * 10)
log.Println("Job 1 done...")
},
// Job 2
func(context.Context, chan error) {
time.Sleep(time.Millisecond * 5)
log.Println("Job 2 done...")
},
)
log.Println("All jobs done...")
Installation
go get -u github.com/arunsworld/nursery
Notes on structured concurrency, or: Go statement considered harmful is an article that compares the dangers of goto with the go statement.
While I don't necessarily agree with the entire content I can appreciate that even with Go's high-level abstraction of concurrency using Goroutines, Channels & the select statement it is possible to end up with unreadable code, deadlocks, leaked goroutines, race conditions and poor error handling.
Implementing a higher-level abstraction for the use-cases mentioned is very straightforward in Go and this simple package provides just that.
The following functions are provided:
RunConcurrently(jobs ...ConcurrentJob) error
: takes an array ofConcurrentJob
s and runs them concurrently ensuring that all jobs are completed before the call terminates. If all jobs terminate cleanly error is nil; otherwise the first non-nil error is returned.RunConcurrentlyWithContext(parentCtx context.Context, jobs ...ConcurrentJob) error
: is the RunConcurrently behavior but additionally wraps a context that's passed in allowing cancellations of the parentCtx to get propagated.RunMultipleCopiesConcurrently(copies int, job ConcurrentJob) error
: makes copies of the given job and runs them concurrently. This is useful for cases where we want to execute multiple slow consumers taking jobs from a channel until the job is finished. The channel itself can be fed by a producer that is run concurrently with the job running the consumers. Each job's context is also passed an unique index with keynursery.JobID
- a 0 based int - that maybe used as a job identity if required.RunMultipleCopiesConcurrentlyWithContext(ctx context.Context, copies int, job ConcurrentJob) error
: is the RunMultipleCopiesConcurrently behavior with a context that allows cancellation to be propagated to the jobs.RunUntilFirstCompletion(jobs ...ConcurrentJob) error
: takes an array ofConcurrentJob
s and runs them concurrently but terminates after the completion of the earliest completing job. A key point here is that despite early termination it blocks until all jobs have terminated (ie. released any used resources). If all jobs terminate cleanly error is nil; otherwise the first non-nil error is returned.RunUntilFirstCompletionWithContext(parentCtx context.Context, jobs ...ConcurrentJob) error
: is the RunUntilFirstCompletion behavior but additionally wraps a context that's passed in allowing cancellations of the parentCtx to get propagated.RunConcurrentlyWithTimeout(timeout time.Duration, jobs ...ConcurrentJob) error
: is similar in behavior toRunConcurrently
except it also takes a timeout and can cause the function to terminate earlier if timeout has expired. As before we wait for all jobs to have cleanly terminated.RunUntilFirstCompletionWithTimeout(timeout time.Duration, jobs ...ConcurrentJob) error
: is similar in behavior toRunUntilFirstCompletion
with an additional timeout clause.
ConcurrentJob
is a simple function that takes a context and error channel. We need to ensure that we're listening to the Done()
channel on context and if invoked to clean-up resources and bail out. Errors are to be published to the error channel for proper handling.
Note: while this package simplifies the semantics of defining and executing concurrent code it cannot protect against bad concurrent programming such as using shared resources across jobs leading to data corruption or panics due to race conditions.
You may also be interested in reading Structured Concurrency in Go.
The library includes a utility function: IsContextDone(context.Context)
to check if the passed in context is done or not. This can be used as a guard clause in a for loop within a ConcurrentJob using the passed in context to decide whether to stop processing and return or continue.