github gammazero/workerpool v1.3.0

3 hours ago

workerpool v1.3.0

This release adds DoWait, fixes a data race between Do and Stop, and fixes several pacer pause bugs. There are no breaking API changes. The minimum Go version is still 1.26.

New

  • DoWait enqueues a task and waits for it to be executed. Unlike SubmitWait, it returns an error instead of panicking:

    • It returns ErrStopped if the worker pool is already stopped.
    • It returns ErrStopped if Stop abandons the task before it runs, instead of blocking forever.
    • With StopWait, the queued task runs before DoWait returns.

    (#104)

Behavior changes

  • SubmitWait panics instead of hanging when Stop abandons its task. SubmitWait now wraps DoWait and panics with its error. Previously, if Stop was called while a SubmitWait task was still queued, SubmitWait blocked forever. It now panics with ErrStopped. Use DoWait if tasks may be submitted while the pool is stopping. (#104)
  • pacer.Pause may wait up to one pacing delay. Pause now waits for any caller already in Next to be released before it takes effect. This is what makes Pause reliable (see Fixes), and it never waits more than one delay.

Fixes

  • Do no longer races with Stop. Do sent on the internal task queue while Stop could be closing it, which the race detector reports. Do is now safe to call concurrently with Stop or StopWait: a task submitted while the pool is stopping is either accepted or rejected with ErrStopped. There is no measurable performance cost. (#103)
  • Stopped no longer blocks while a Pause is waiting for an earlier pause. (#103)
  • WaitingQueueSize uses a 64-bit counter. The waiting queue is unbounded, and the count previously used 32 bits. (#103)
  • pacer.Pause now stops tasks from being released. Previously, the first task after Pause could still be released. After Pause returns, no paced task starts until Resume. (#100)
  • pacer.Pause no longer waits behind every queued task. With many callers waiting in Next, Pause used to wait for all of them to be released first. It now waits for at most one. (#100)
  • pacer.Resume does nothing when the pacer is not paused. Previously it blocked forever. (#101)

Documentation

  • Submit and SubmitWait are documented as panicking wrappers around Do and DoWait, for code where submitting to a stopped pool is a programming error. They are not deprecated. (#104)
  • ErrStopped, calling Do during Stop, and tasks that panic are now documented. (#103)
  • The README and pacer examples use Do (#104), and the README install instructions are updated (#102).
  • Package doc headings use Go doc comment syntax. (#102)

Tests

  • The pacer tests and TestDoConcurrentStop run under testing/synctest, so they no longer wait in real time. (#100, #104)

Full Changelog: v1.2.2...v1.3.0

Don't miss a new workerpool release

NewReleases is sending notifications on new releases.