fibby
A tiny library for node that helps you use fibers with node-style callbacks and works similarly to suspend
usage examples
Spawn a fiber task. From within your task, call your async functions with yield and pass them a resume function instead of a callback:
fibby;
Handle errors with try
/catch
, or as return results via
resume.nothrow
fibby;
Dont like nested parens? Want to keep things brief? Use resume.t
instead of resume()
and resume.nt
instead of resume.nothrow()
Want to catch all uncaught exceptions? You can pass a callback argument to
fibby.run
:
fibby;
You can also use fibby
instead to create a function which
can accept multiple arguments and a callback. The arguments will be
passed to your fiber right after the first resume
argument
var getLine = fibby; ;
note: make sure that you pass the callback last.
Notice how if you return a value at the end of your fiber, it will be passed as a result to the callback. If you return undefined, the callback will not be called.
Your async functions call the callback with more than 2 arguments? Not a problem - the yield call from within your task will return an array instead.
{ ;} fibby
Look in test/index.js
for more examples and tests.
thanks
jmar777 for his awesome suspend library which served as the base for fibby
license
MIT