You shouldn't be looking at what happens around the call that creates the fiber but rather at what happens inside the fiber. Once you are inside the fiber you can program in sync style. For example:
function f1() { console.log('wait... ' + new Date); sleep(1000); console.log('ok... ' + new Date); } function f2() { f1(); f1(); } Fiber(function() { f2(); }).run();
Inside the fiber you call f1
, f2
and sleep
as if they were sync.
In a typical web application, you will create the Fiber in your HTTP request dispatcher. Once you've done that you can write all your request handling logic in sync style, even if it calls async functions (fs, databases, etc.).