Skip to content

Commit

Permalink
fix: unshift with worker throwing error (#77) (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
aguegu committed Dec 18, 2023
1 parent be3943a commit c77c9cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions queue.js
Expand Up @@ -118,6 +118,7 @@ function fastqueue (context, worker, concurrency) {
current.release = release
current.value = value
current.callback = done || noop
current.errorHandler = errorHandler

if (_running === self.concurrency || self.paused) {
if (queueHead) {
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Expand Up @@ -564,3 +564,19 @@ test('push with worker throwing error', function (t) {
t.match(err.message, /test error/, 'error message should be "test error"')
})
})

test('unshift with worker throwing error', function (t) {
t.plan(5)
var q = buildQueue(function (task, cb) {
cb(new Error('test error'), null)
}, 1)
q.error(function (err, task) {
t.ok(err instanceof Error, 'global error handler should catch the error')
t.match(err.message, /test error/, 'error message should be "test error"')
t.equal(task, 42, 'The task executed should be passed')
})
q.unshift(42, function (err) {
t.ok(err instanceof Error, 'unshift callback should catch the error')
t.match(err.message, /test error/, 'error message should be "test error"')
})
})

0 comments on commit c77c9cd

Please sign in to comment.