Skip to content

Instantly share code, notes, and snippets.

@lleo
Last active August 29, 2015 13:58
Show Gist options
  • Save lleo/9928771 to your computer and use it in GitHub Desktop.
Save lleo/9928771 to your computer and use it in GitHub Desktop.
Example use of ES6 generator with 'co' and 'thunkify' modules to read four files in in parallel.
#!/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, thunks
thunks = fns.map(function(fn){
return readFile(fn)
})
contents = (yield thunks).join('')
console.log(contents)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment