Skip to content

Commit

Permalink
handle nextTick
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Apr 8, 2021
1 parent 449e510 commit 36457b9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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)
})
})
Expand All @@ -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)
Expand Down

0 comments on commit 36457b9

Please # to comment.