Skip to content

Commit

Permalink
Emit drain event after pause/resume combo
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Feb 5, 2024
1 parent 22d8dc1 commit 1684b5c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions queue.js
Expand Up @@ -93,6 +93,11 @@ function fastqueue (context, worker, _concurrency) {
function resume () {
if (!self.paused) return
self.paused = false
if (queueHead === null) {
_running++
release()
return
}
for (; queueHead && _running < _concurrency;) {
_running++
release()
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Expand Up @@ -624,3 +624,19 @@ test('unshift with worker throwing error', function (t) {
t.match(err.message, /test error/, 'error message should be "test error"')
})
})

test('pause/resume should trigger drain event', function (t) {
t.plan(1)

var queue = buildQueue(worker, 1)
queue.pause()
queue.drain = function () {
t.pass('drain should be called')
}

function worker (arg, cb) {
cb(null, true)
}

queue.resume()
})

0 comments on commit 1684b5c

Please sign in to comment.