From 0ac7a8ea2d1807c6ba8e6bf74475b26ed49f133f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 10 Apr 2024 10:47:10 +0200 Subject: [PATCH] fix: defer errors with setImmediate --- lib/api/readable.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/api/readable.js b/lib/api/readable.js index 796c237e889..f0e4dbd34bc 100644 --- a/lib/api/readable.js +++ b/lib/api/readable.js @@ -63,9 +63,7 @@ class BodyReadable extends Readable { // tick as it is created, then a user who is waiting for a // promise (i.e micro tick) for installing a 'error' listener will // never get a chance and will always encounter an unhandled exception. - // - tick => process.nextTick(fn) - // - micro tick => queueMicrotask(fn) - queueMicrotask(() => { + setImmediate(() => { callback(err) }) }