Skip to content

Instantly share code, notes, and snippets.

@lleo
Last active January 31, 2016 15:10
Show Gist options
  • Save lleo/9928733 to your computer and use it in GitHub Desktop.
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.
#!/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