Skip to content

Instantly share code, notes, and snippets.

@dchester
Last active March 26, 2016 23:56
Show Gist options
  • Save dchester/404d76b2a8543330d227 to your computer and use it in GitHub Desktop.
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
 
> [email protected] postinstall /home/dchester/test/node_modules/generator-async/node_modules/jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js

[email protected] node_modules/generator-async
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])

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