Skip to content

Instantly share code, notes, and snippets.

@petersirka
Created May 29, 2016 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petersirka/12c461622196a958dba543b9e1b0d8e6 to your computer and use it in GitHub Desktop.
Save petersirka/12c461622196a958dba543b9e1b0d8e6 to your computer and use it in GitHub Desktop.
Total.js Generators and Promisies
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