From 9ce0d9971c7b062763a0d145694233576522d230 Mon Sep 17 00:00:00 2001 From: lionel-rowe Date: Sun, 2 Nov 2025 18:22:39 +0800 Subject: [PATCH] fix: Always yield to event loop before nextTick for async versions --- index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index f91fff4..4a19b3d 100644 --- a/index.js +++ b/index.js @@ -326,19 +326,17 @@ export function truncates(password) { } /** - * Continues with the callback on the next tick. + * Continues with the callback after yielding to the event loop. * @function * @param {function(...[*])} callback Callback to execute * @inner */ var nextTick = - typeof process !== "undefined" && - process && - typeof process.nextTick === "function" - ? typeof setImmediate === "function" - ? setImmediate - : process.nextTick - : setTimeout; + typeof setImmediate === "function" + ? setImmediate + : typeof scheduler === "object" && typeof scheduler.postTask === "function" + ? scheduler.postTask.bind(scheduler) + : setTimeout; /** Calculates the byte length of a string encoded as UTF8. */ function utf8Length(string) {