Last active
January 31, 2016 15:10
-
-
Save lleo/9928733 to your computer and use it in GitHub Desktop.
Example use of ES6 generator with 'co' and 'thunkify' modules to read four files in series.
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
#!/usr/bin/env node --harmony-generators | |
var fs = require('fs') | |
, thunkify = require('thunkify') | |
, co = require('co') | |
, readFile = thunkify(fs.readFile) | |
, fns = ["file0.txt", "file1.txt" | |
, "file2.txt", "file3.txt"] | |
co(function*(){ | |
var contents = '', i | |
for (i=0; i<fns.length; i+=1) { | |
contents += yield readFile(fns[i]) | |
} | |
console.log(contents) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment