Skip to content

Instantly share code, notes, and snippets.

@bjouhier
Created January 24, 2017 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjouhier/7d660269b6fae13b7e33081d391c665d to your computer and use it in GitHub Desktop.
Save bjouhier/7d660269b6fae13b7e33081d391c665d to your computer and use it in GitHub Desktop.
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
Copy link
Author

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