Skip to content

Instantly share code, notes, and snippets.

@wearhere
Created July 22, 2015 19:43
Show Gist options
  • Save wearhere/4f07d298d077da9dcb2d to your computer and use it in GitHub Desktop.
Save wearhere/4f07d298d077da9dcb2d to your computer and use it in GitHub Desktop.
What a fiber-using function looks like if you let the fiber call `done` for you. Compare https://gist.github.com/wearhere/825a51a6a16a4337733f. More info at https://www.mixmax.com/blog/node-fibers-using-synchronize-js.
function processFile(fileName, done) {
sync.fiber(function() {
// No need for try-catches even, assuming that you're ok with `done` handling errors!
var data = /* first `sync` call */;
return /* second `sync` call */;
}, done);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment