Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: nextTick timing regression (#1573)
* fix: nextTick timing regression (cherry picked from commit 65ecb6f)
- Loading branch information
1 parent
61c954e
commit 7f35078
Showing
5 changed files
with
31 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = | ||
typeof setImmediate === "function" | ||
? setImmediate | ||
: (function() { | ||
var queue = []; | ||
var win = window; | ||
var msg = "" + Math.random(); | ||
win.addEventListener("message", function(ev) { | ||
if (ev.data === msg) { | ||
var callbacks = queue; | ||
queue = []; | ||
for (var i = 0; i < callbacks.length; i++) { | ||
callbacks[i](); | ||
} | ||
} | ||
}); | ||
return function(callback) { | ||
if (queue.push(callback) === 1) { | ||
win.postMessage(msg, "*"); | ||
} | ||
}; | ||
})(); |