Last active
December 15, 2015 21:49
-
-
Save wizardwerdna/5328792 to your computer and use it in GitHub Desktop.
A plugin substitute for nextTick that avoids the "recursive nextTick" bug. After enqueue = require('./enqueue').enqueue, simply replace every call to nextTick in your program that might begin a recursive call, and replace "process.nextTick" with enqueue.
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
root = (exports ? this) | |
nextTick = process.nextTick | |
root.enqueue = do(queue=undefined)-> | |
trampoline = -> | |
while next = queue.shift() | |
next() | |
queue = undefined | |
(f) -> | |
if queue? | |
queue.push f | |
else | |
queue = [f] | |
nextTick -> trampoline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment