Created
October 18, 2016 17:10
-
-
Save mlconnor/346a2a4ebc21b7d96e9fa3ca0e4a7c78 to your computer and use it in GitHub Desktop.
Finally, a way to do node.js synchronously
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
'use strict'; | |
var fs = require('fs'); | |
var co = require('co'); | |
var Promise = require('bluebird'); | |
var readFile = Promise.promisify(require("fs").readFile); | |
function* doAsyncStuff() { | |
var file1 = yield readFile('testx.txt',{encoding:'utf8'}); | |
return file1; | |
} | |
co( function *() { | |
var file1 = yield doAsyncStuff(); | |
console.log('done ' + file1); | |
}).catch( function(e) { | |
console.log(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment