Categorygithub.com/yarcode/workerpool
modulepackage
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)

# Functions

AddContext replaces the default context (context.Background()) with the specified one only for this job.
AddLogger replaces job context zerolog logger with the specified one.
AddPanicRecovery to your job.
AddPostRun middleware allows you to add some logic once was completed or failed.
AddRetry middleware allows you to apply retry strategies to your job.
AddTimeout middleware allows you to add timeout to your job.
New Pool constructor.
WithLogger replaces the default logger with the specified one.

# Structs

No description provided by the author

# Type aliases

Job is a function that receives context and being run asynchronously by the worker pool.
PoolOption is a functional parameter used in constructor.