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
-
DoWaitenqueues a task and waits for it to be executed. UnlikeSubmitWait, it returns an error instead of panicking:- It returns
ErrStoppedif the worker pool is already stopped. - It returns
ErrStoppedifStopabandons the task before it runs, instead of blocking forever. - With
StopWait, the queued task runs beforeDoWaitreturns.
(#104)
- It returns
Behavior changes
SubmitWaitpanics instead of hanging whenStopabandons its task.SubmitWaitnow wrapsDoWaitand panics with its error. Previously, ifStopwas called while aSubmitWaittask was still queued,SubmitWaitblocked forever. It now panics withErrStopped. UseDoWaitif tasks may be submitted while the pool is stopping. (#104)pacer.Pausemay wait up to one pacing delay.Pausenow waits for any caller already inNextto be released before it takes effect. This is what makesPausereliable (see Fixes), and it never waits more than one delay.
Fixes
Dono longer races withStop.Dosent on the internal task queue whileStopcould be closing it, which the race detector reports.Dois now safe to call concurrently withStoporStopWait: a task submitted while the pool is stopping is either accepted or rejected withErrStopped. There is no measurable performance cost. (#103)Stoppedno longer blocks while aPauseis waiting for an earlier pause. (#103)WaitingQueueSizeuses a 64-bit counter. The waiting queue is unbounded, and the count previously used 32 bits. (#103)pacer.Pausenow stops tasks from being released. Previously, the first task afterPausecould still be released. AfterPausereturns, no paced task starts untilResume. (#100)pacer.Pauseno longer waits behind every queued task. With many callers waiting inNext,Pauseused to wait for all of them to be released first. It now waits for at most one. (#100)pacer.Resumedoes nothing when the pacer is not paused. Previously it blocked forever. (#101)
Documentation
SubmitandSubmitWaitare documented as panicking wrappers aroundDoandDoWait, for code where submitting to a stopped pool is a programming error. They are not deprecated. (#104)ErrStopped, callingDoduringStop, and tasks that panic are now documented. (#103)- The README and
pacerexamples useDo(#104), and the README install instructions are updated (#102). - Package doc headings use Go doc comment syntax. (#102)
Tests
- The
pacertests andTestDoConcurrentStoprun undertesting/synctest, so they no longer wait in real time. (#100, #104)
Full Changelog: v1.2.2...v1.3.0