Skip to content

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

License

Notifications You must be signed in to change notification settings

yarcode/workerpool

Repository files navigation

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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published