Created
December 15, 2015 15:43
-
-
Save ntrrgc/ac3df462c528aac22166 to your computer and use it in GitHub Desktop.
fibrous example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fibrous = require('fibrous'); | |
var fs = require('fs'); | |
var wait = function wait(ms, callback) { | |
setTimeout(callback, ms); | |
}; | |
function getSomething() { | |
var a = fs.sync.readFile('/tmp/a', 'utf8'); | |
var b = fs.sync.readFile('/tmp/b', 'utf8'); | |
console.log('Read a and b'); | |
console.log('Counting...'); | |
for (var i = 1; i <= 3; i++) { | |
console.log(i); | |
wait.sync(400); | |
} | |
return a + b | |
} | |
var main = fibrous(function main() { | |
try { | |
console.log(getSomething()) | |
} catch (ex) { | |
console.log(ex.stack); | |
} | |
}); | |
main(function () { | |
console.log('Program finished'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment