Created
February 14, 2015 02:07
-
-
Save danfinlay/83a16d4e371a58b951ea to your computer and use it in GitHub Desktop.
ES6 Fun Example Using Generators & Block Comments
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
| 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