Skip to content

Instantly share code, notes, and snippets.

@danfinlay
Created February 14, 2015 02:07
Show Gist options
  • Select an option

  • Save danfinlay/83a16d4e371a58b951ea to your computer and use it in GitHub Desktop.

Select an option

Save danfinlay/83a16d4e371a58b951ea to your computer and use it in GitHub Desktop.
ES6 Fun Example Using Generators & Block Comments
var fs = require('fs')
var path = require('path')
run(function * (done){
var files = yield fs.readdir(__dirname, done);
var file
for( var i = 0; i < files.length; i++ ){
file = files[i];
var body = yield fs.readFile(path.join(__dirname, file), done);
console.log(`
--------------------
The file named ${file} has a contents of:
---------------------
${body}
`);
}
})
function run (generator) {
var it = generator(go);
function go (err, results){
if(err){
it.throw(err);
} else {
it.next(results);
}
}
go();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment