2. Fibers
● lightweight threads
● co-operative multitasking
○ still using one event loop
● individual stack, shared heap
○ require a bit of additional memory for stacks
● similar to generators (in ES6)
○ but no need to mark each yielding method
3. Fibers usage example
function sleep(ms) {
var fiber = Fiber.current;
setTimeout(function() {
fiber.run();
}, ms);
Fiber.yield();
}
5. CommonJS
● Set of specifications
○ Modules, Packages, Unit Testing
○ Binary, IO, Filesystem, JSGI, etc.
● Implemented by RingoJS and others
○ Ringo runs on top of the JVM
● Node supports the first 3, but not others
because they assume sync. I/O
6. Common Node
● Implements CommonJS specs using Fibers
on top of Node
● Allows for code reuse with RingoJS
● Simplifies business logic & debugging
○ supports for, exceptions etc. for flow control
● Performance: 80%-120% of Node
○ Uses a bit more memory e.g. 28MB vs. 32MB
12. Common Node at StartHQ
● Use it for everything
○ API, static resources
○ background processing
○ command line tools
● Extractors API
● Sentry stack traces
13. Pitfalls
● Trying to yield or resume outside fiber
● Using async libs with fibers, such as Express
● Writing to global variables
● Separate fiber instance per dependency
● Unreliable third party packages
○ Throws into event loop & crashed program