Skip to content

Commit 41bc929

Browse files
author
Daniel Wirtz
committed
cross node/browser nexttick
1 parent 60da50b commit 41bc929

3 files changed

Lines changed: 63 additions & 37 deletions

File tree

bcrypt.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,19 @@
553553
}
554554
}
555555

556+
/**
557+
* Continues with the callback on the next tick.
558+
* @param {function(...[*])} callback Callback to execute
559+
* @private
560+
*/
561+
function _nextTick(callback) {
562+
if (typeof process !== 'undefined' && typeof process.nextTick === 'function') {
563+
process.nextTick(callback);
564+
} else {
565+
setTimeout(callback, 0);
566+
}
567+
}
568+
556569
/**
557570
* Internaly crypts a string.
558571
* @param {Array.<number>} b Bytes to crypt
@@ -619,7 +632,7 @@
619632
}
620633
}
621634
if (callback) {
622-
process.nextTick(next);
635+
_nextTick(next);
623636
}
624637
return null;
625638
}
@@ -799,7 +812,7 @@
799812
if (typeof callback != 'function') {
800813
throw(new Error("Illegal or missing 'callback': "+callback));
801814
}
802-
process.nextTick(function() { // Pretty thin, but salting is fast enough
815+
_nextTick(function() { // Pretty thin, but salting is fast enough
803816
try {
804817
var res = bcrypt.genSaltSync(rnd);
805818
callback(null, res);

0 commit comments

Comments
 (0)