From 3e10bb85bcd9f40f8f826789334c21e4ae4430a8 Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 10 Feb 2023 11:50:49 +0100 Subject: [PATCH] Fixed error in queue when timeout is 0 (#200) --- boot.js | 9 +++++++-- test/async-await.test.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/boot.js b/boot.js index c3e1d62..54e1f03 100644 --- a/boot.js +++ b/boot.js @@ -426,10 +426,15 @@ function callWithCbOrNextTick (func, cb) { } } else { if (this._timeout === 0) { + const wrapCb = (err) => { + this._error = err + cb(this._error) + } + if (func.length === 2) { - func(err, cb) + func(err, wrapCb) } else { - func(err, context, cb) + func(err, context, wrapCb) } } else { timeoutCall.call(this, func, err, context, cb) diff --git a/test/async-await.test.js b/test/async-await.test.js index 01ed129..6d3e3c2 100644 --- a/test/async-await.test.js +++ b/test/async-await.test.js @@ -305,3 +305,17 @@ test('skip override with promise', (t) => { return fn } }) + +test('ready queue error', async (t) => { + const app = boot() + app.use(first) + + async function first (s, opts) {} + + app.ready(function (_, worker, done) { + const error = new Error('kaboom') + done(error) + }) + + await t.rejects(app.ready(), { message: 'kaboom' }) +})