From 36457b9fecfd1e128c8e9884a57e277649679832 Mon Sep 17 00:00:00 2001 From: "Calvin W. Metcalf" Date: Thu, 8 Apr 2021 13:35:05 -0400 Subject: [PATCH] handle nextTick --- lib/async.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/async.js b/lib/async.js index 9ef67c3..29962c3 100644 --- a/lib/async.js +++ b/lib/async.js @@ -39,7 +39,22 @@ function checkNative (algo) { checks[algo] = prom return prom } - +var nextTick +function getNextTick () { + if (nextTick) { + return nextTick + } + if (global.process && global.process.nextTick) { + nextTick = global.process.nextTick + } else if (global.queueMicrotask) { + nextTick = global.queueMicrotask + } else if (global.setImmediate) { + nextTick = global.setImmediate + } else { + nextTick = global.setTimeout + } + return nextTick +} function browserPbkdf2 (password, salt, iterations, length, algo) { return subtle.importKey( 'raw', password, { name: 'PBKDF2' }, false, ['deriveBits'] @@ -59,11 +74,11 @@ function browserPbkdf2 (password, salt, iterations, length, algo) { function resolvePromise (promise, callback) { promise.then(function (out) { - process.nextTick(function () { + getNextTick()(function () { callback(null, out) }) }, function (e) { - process.nextTick(function () { + getNextTick()(function () { callback(e) }) }) @@ -78,7 +93,7 @@ module.exports = function (password, salt, iterations, keylen, digest, callback) var algo = toBrowser[digest.toLowerCase()] if (!algo || typeof global.Promise !== 'function') { - return process.nextTick(function () { + return getNextTick()(function () { var out try { out = sync(password, salt, iterations, keylen, digest)