Skip to content

A resilient worker pool for Go that stops execution after a configurable number of errors. Supports panic recovery and concurrent task processing.

License

Notifications You must be signed in to change notification settings

Averlex/workerpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workerpool

Go version Go Reference Go Report Card License

A resilient worker pool for Go that stops execution after a configurable number of errors. Supports panic recovery and concurrent task processing.

Features

  • ✅ Configurable number of workers (n)
  • ✅ Stop execution after m errors (or ignore errors if m <= 0)
  • ✅ Panic recovery: panics are treated as errors, workers continue
  • ✅ Thread-safe

Usage

import "github.com/Averlex/workerpool"

tasks := []workerpool.Task{
    func() error { /* task 1 */ return nil },
    func() error { /* task 2 */ return errors.New("failed") },
    func() error { /* task 3 */ panic("oops") },
    // ...
}

// Run with 4 workers, stop after 2 errors.
err := workerpool.Run(tasks, 4, 2)
if err == workerpool.ErrErrorsLimitExceeded {
    log.Println("Stopped: too many errors")
}

Interface

type Task func() error

Run(tasks []Task, n, m int) error
  • Run(tasks []Task, n, m int) error
    • n: number of concurrent workers.
    • m: maximum number of errors before stopping. If m <= 0, all errors are ignored.
  • Returns:
  • nil — all tasks completed successfully.
  • ErrNoTasks — no tasks provided.
  • ErrNoWorkersn <= 0.
  • ErrErrorsLimitExceeded — more than m errors occurred.

Error Handling

  • Each error returned by a task counts as one error.
  • Each panic is recovered and also counts as one error.
  • As soon as the error count exceeds m, no new tasks are started.

Installation

go get github.com/Averlex/workerpool

About

A resilient worker pool for Go that stops execution after a configurable number of errors. Supports panic recovery and concurrent task processing.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages