Skip to content

Instantly share code, notes, and snippets.

@dchester
Last active March 26, 2016 23:56
Show Gist options
  • Select an option

  • Save dchester/404d76b2a8543330d227 to your computer and use it in GitHub Desktop.

Select an option

Save dchester/404d76b2a8543330d227 to your computer and use it in GitHub Desktop.
Example with fs module and async-generator
var async = require('generator-async');
// load `fs` with async's `require`
var fs = async.require('fs');
async.run(function*() {
// read a file
var passwd = yield fs.readFile('/etc/passwd');
// then read another file
var group = yield fs.readFile('/etc/group');
// then spit out the contents of both files
console.log(passwd, group);
});
$ node -v
v4.2.6

$ npm install generator-async
 
> jsonpath@0.2.2 postinstall /home/dchester/test/node_modules/generator-async/node_modules/jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js

generator-async@0.1.3 node_modules/generator-async
├── methods@1.1.1
├── callsite@1.0.0
├── async@0.9.0
├── esprima@2.7.2
├── package-path@0.0.1
├── semver@4.2.0
├── jsonpath@0.2.2 (underscore@1.7.0, esprima@1.2.2, static-eval@0.2.3, jison@0.4.13)
└── module-async-mapper@0.1.3 (esprima@2.2.0, mkdirp@0.5.1, jsonpath@0.1.5)

$ node example.js 
<Buffer ...>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment