Skip to content

Instantly share code, notes, and snippets.

@xcoderzach
Created March 28, 2011 05:18
Show Gist options
  • Save xcoderzach/890036 to your computer and use it in GitHub Desktop.
Save xcoderzach/890036 to your computer and use it in GitHub Desktop.
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