Created
March 28, 2011 05:18
-
-
Save xcoderzach/890036 to your computer and use it in GitHub Desktop.
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
require('fibers') | |
function sleep(ms) { | |
var fiber = Fiber.current; | |
setTimeout(function() { | |
fiber.run() | |
}, ms) | |
yield() | |
} | |
var x | |
Fiber(function() { | |
x = 5 | |
sleep(0) | |
console.log(x) // this prints borked! | |
}).run() | |
process.nextTick(function() { | |
x = "borked!" | |
}) | |
// as opposed to this | |
var x | |
(function() { | |
x = 5 | |
sleep(0, function() { | |
console.log(x) // this also prints borked! which isn't as surprising | |
}) | |
}()) | |
process.nextTick(function() { | |
x = "borked!" | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment