O'Reilly logo

Async JavaScript by Trevor Burnham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Node-Fibers

While the other projects I’ve listed here merely compile to plain JavaScript, node-fibers actually extends the language understood by the Node runtime by adding threadlike constructs called fibers (http://en.wikipedia.org/wiki/Fiber_(computer_science)). A fiber can yield to other fibers, suspending its own execution until an event causes it run again.

 
var​ fiber = Fiber.current;
 
console.log(​'Yielding until the timeout elapses...'​)
 
setTimeout(​function​() {
 
fiber.run();
 
}, 1000);
 
Fiber.yield();
 
console.log(​'...1 second later'​);

The main advantage of node-fibers over JavaScript precompilers is debugging. The line numbers in node-fiber stack traces correspond to the line numbers in node-fiber source code, and thrown exceptions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required