Skip to content

Instantly share code, notes, and snippets.

@wearhere
Last active August 29, 2015 14:25
Show Gist options
  • Save wearhere/825a51a6a16a4337733f to your computer and use it in GitHub Desktop.
Save wearhere/825a51a6a16a4337733f to your computer and use it in GitHub Desktop.
What a fiber-using function would look like if you called `done` rather than letting the fiber do it for you. Compare https://gist.github.com/wearhere/4f07d298d077da9dcb2d. More info at https://www.mixmax.com/blog/node-fibers-using-synchronize-js.
function processFile(fileName, done) {
sync.fiber(function() {
var data;
try {
data = /* first `sync` call */;
} catch(e) {
done(e);
return;
}
var processedData;
try {
processedData = /* second `sync` call */;
done(null, processedData);
} catch(e) {
done(e);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment