Categorygithub.com/yarcode/workerpool
repositorypackage
1.0.0
Repository: https://github.com/yarcode/workerpool.git
Documentation: pkg.go.dev

# README

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)