@@ -39,7 +39,22 @@ function checkNative (algo) {
39
39
checks [ algo ] = prom
40
40
return prom
41
41
}
42
-
42
+ var nextTick
43
+ function getNextTick ( ) {
44
+ if ( nextTick ) {
45
+ return nextTick
46
+ }
47
+ if ( global . process && global . process . nextTick ) {
48
+ nextTick = global . process . nextTick
49
+ } else if ( global . queueMicrotask ) {
50
+ nextTick = global . queueMicrotask
51
+ } else if ( global . setImmediate ) {
52
+ nextTick = global . setImmediate
53
+ } else {
54
+ nextTick = global . setTimeout
55
+ }
56
+ return nextTick
57
+ }
43
58
function browserPbkdf2 ( password , salt , iterations , length , algo ) {
44
59
return subtle . importKey (
45
60
'raw' , password , { name : 'PBKDF2' } , false , [ 'deriveBits' ]
@@ -59,11 +74,11 @@ function browserPbkdf2 (password, salt, iterations, length, algo) {
59
74
60
75
function resolvePromise ( promise , callback ) {
61
76
promise . then ( function ( out ) {
62
- process . nextTick ( function ( ) {
77
+ getNextTick ( ) ( function ( ) {
63
78
callback ( null , out )
64
79
} )
65
80
} , function ( e ) {
66
- process . nextTick ( function ( ) {
81
+ getNextTick ( ) ( function ( ) {
67
82
callback ( e )
68
83
} )
69
84
} )
@@ -78,7 +93,7 @@ module.exports = function (password, salt, iterations, keylen, digest, callback)
78
93
var algo = toBrowser [ digest . toLowerCase ( ) ]
79
94
80
95
if ( ! algo || typeof global . Promise !== 'function' ) {
81
- return process . nextTick ( function ( ) {
96
+ return getNextTick ( ) ( function ( ) {
82
97
var out
83
98
try {
84
99
out = sync ( password , salt , iterations , keylen , digest )
0 commit comments