Package workerpool provides a service for running small parts of code (called jobs) in a background.
Jobs could have contexts, timeouts, rich retry strategies.
pool := New()
pool.Start()
job := func(ctx context.Context) error {
fmt.Println("hello")
return nil
}
pool.Run(job)
pool := New()
pool.Start()
job := func(ctx context.Context) error {
//
// some tricky logic goes here
//
return nil
}
// add 3 seconds timeout for a job execution
job = AddTimeout(job, time.Second*3)
// retry job execution withing 5 attempts
job = AddRetry(job, strategy.Limit(5))
pool.Run(job)