Skip to content

Commit

Permalink
fix: internet explorer compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Jan 10, 2021
1 parent b6d082c commit 3331c2c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/internal/streams/next-tick-browser.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';

module.exports = function (cb) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
module.exports = function nextTick2 (cb) {
var args = arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null;
var handle = function () {
cb.apply(null, args);
};

// Base on https://github.com/feross/queue-microtask/blob/master/index.js by feross
if(typeof queueMicrotask === 'function') {
queueMicrotask(()=>{
cb.apply(null, args)
});
} else {
queueMicrotask(handle);
return;
}
if (global.Promise === undefined) {
Promise.resolve()
.then(() => {
cb.apply(null, args)
})
.catch(err => setTimeout(() => { throw err }, 0))
.then(handle)
.catch(function (err) {
setTimeout(function () { throw err }, 0);
});
return;
}
};
setTimeout(handle, 0);
};

0 comments on commit 3331c2c

Please sign in to comment.