Skip to content

Instantly share code, notes, and snippets.

@lxe
Created December 27, 2014 01:20
Show Gist options
  • Select an option

  • Save lxe/99fbb4efb3b8b1ae7ae2 to your computer and use it in GitHub Desktop.

Select an option

Save lxe/99fbb4efb3b8b1ae7ae2 to your computer and use it in GitHub Desktop.
var request = require('request')
, JSONStream = require('JSONStream')
, es = require('event-stream')
var req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'});
var parse = JSONStream.parse('rows.*');
var map = es.map(function (data) {
// console.log(data);
return data;
});
req.on('finish', function () {
console.log('req finish event fired');
});
req.on('end', function () {
console.log('req end event fired');
});
parse.on('finish', function () {
console.log('parse finish event fired');
});
parse.on('end', function () {
console.log('parse end event fired');
});
map.on('finish', function () {
console.log('map finish event called');
});
map.on('end', function () {
console.log('map end event called');
});
var pipeline = req
.pipe(parse)
.pipe(map)
.pipe(process.stdout); // I know this doesn't make sense for object streams, but whatever
pipeline.on('finish', function () {
console.log('pipeline finish event called');
});
pipeline.on('end', function () {
console.log('pipeline end event called');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment