Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.17 KB

README.md

File metadata and controls

49 lines (33 loc) · 1.17 KB

workerpool

codecov golangci GoDoc Go Report Card

Package workerpool provides a service for running small parts of code (called jobs) in a background.

Jobs could have contexts, timeouts, rich retry strategies.

Examples

pool := New()
pool.Start()

job := func(ctx context.Context) error {
    fmt.Println("hello")
    return nil
}

pool.Run(job)

AdvancedUsage

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)