Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1211e9a

Browse files
authored
fix: Always yield to event loop before nextTick for async versions (#164)
1 parent 28e5103 commit 1211e9a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,17 @@ export function truncates(password) {
326326
}
327327

328328
/**
329-
* Continues with the callback on the next tick.
329+
* Continues with the callback after yielding to the event loop.
330330
* @function
331331
* @param {function(...[*])} callback Callback to execute
332332
* @inner
333333
*/
334334
var nextTick =
335-
typeof process !== "undefined" &&
336-
process &&
337-
typeof process.nextTick === "function"
338-
? typeof setImmediate === "function"
339-
? setImmediate
340-
: process.nextTick
341-
: setTimeout;
335+
typeof setImmediate === "function"
336+
? setImmediate
337+
: typeof scheduler === "object" && typeof scheduler.postTask === "function"
338+
? scheduler.postTask.bind(scheduler)
339+
: setTimeout;
342340

343341
/** Calculates the byte length of a string encoded as UTF8. */
344342
function utf8Length(string) {

0 commit comments

Comments
 (0)