Skip to content

A helper to run goroutines in a pool just like in java's or python's pools

License

Notifications You must be signed in to change notification settings

ykhrustalev/goroutinepool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goroutinepool

GoDoc Build Status Go Report Card

Package goroutinepool provides handy functions for running goroutines concurrently similar to multiprocess.Pool in python or concurrency.ThreadPoolExecutor in java.

Example:

ctx := context.Background()

var counter int32

// a simple job to increment a number
increment := func(delta int32) func(context.Context) {
    return func(ctx context.Context) {
        atomic.AddInt32(&counter, delta)
    }
}

// jobs
fns := []func(context.Context){
    increment(1),
    increment(10),
    increment(100),
}

// use two workers
goroutinepool.RunInPool(ctx, 2, fns)

fmt.Println(atomic.LoadInt32(&counter))

// Output:
// 111

About

A helper to run goroutines in a pool just like in java's or python's pools

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages