Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.