Instantly share code, notes, and snippets.

Embed
What would you like to do?
console.log("script begin");
var Fiber = require('fibers');
Fiber(function() {
var fiber = Fiber.current;
setTimeout(function() {
console.log("setTimeout callback begin");
fiber.run();
console.log("setTimeout callback end");
}, 10000)
console.log(">>> before Fiber.yield()");
Fiber.yield();
console.log(">>> after Fiber.yield()");
}).run();
setInterval(function() {
console.log("setInterval callback");
}, 1000);
console.log("script end");
@bjouhier

This comment has been minimized.

Owner

bjouhier commented Jan 24, 2017

Output:

$ node fibers-does-not-block
script begin
>>> before Fiber.yield()
script end
setInterval callback
setInterval callback
setInterval callback
setInterval callback
setInterval callback
setInterval callback
setInterval callback
setInterval callback
setInterval callback
setTimeout callback begin
>>> after Fiber.yield()
setTimeout callback end
setInterval callback
setInterval callback
setInterval callback
setInterval callback
^C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment