Created
May 29, 2016 07:56
-
-
Save petersirka/12c461622196a958dba543b9e1b0d8e6 to your computer and use it in GitHub Desktop.
Total.js Generators and Promisies
This file contains hidden or 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
const Fs = require('fs'); | |
require('total.js'); | |
async(function*() { | |
var a = yield readFile('run.sh'); | |
var b = yield readFile('run.sh'); | |
var c = yield readFile('run.sh'); | |
// var a = yield sync(Fs.readFile)('run.sh'); | |
// var b = yield sync(Fs.readFile)('run.sh'); | |
// var c = yield sync(Fs.readFile)('run.sh'); | |
console.log('----', a); | |
console.log('----', b); | |
console.log('----', c); | |
})(); | |
function readFile(path) { | |
return new Promise(function(resolve, reject) { | |
Fs.readFile(path, function (err, data) { | |
if (err) reject(err); | |
else resolve(data.toString()); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment