Caution
tasq is currently in alpha and not fit for production level use.
tasq
is a high performance worker pool for distributing tasks across a collection of worker
goroutines. tasq
is dynamic in nature and auto scales depending on the number of work available
at any point in time.
If you have a bunch of tasks to do and want an easy way to distribute them in a parallel manner without
the hassle of managing worker dispatching yourself tasq
is for you.
tasq
has built in support for pausing the pool for a given time (configurable via a context
) for improved
error handling scenarios where upstream dependencies may be non functional.
Note
By design tasq
does not propagate errors or return values, tasks should handle their own persistence
by (for example) shovelling their return values into a channel etc.
tasq
follows semantic versioning.
package main
import (
"github.com/symonk/tasq"
"time"
)
func main() {
pool := tasq.New(tasq.WithMaxWorkers(10))
results := make(chan string)
for i := range 100 {
pool.Enqueue(func() {
time.Sleep(time.Second)
results <- fmt.Sprintf("%d", i)
})
}
close(results)
go func() {
for r := range results {
fmt.Println(r)
}
}()
pool.Stop()
}