Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Created August 11, 2015 18:44
Show Gist options
  • Save ben-bradley/340aeaa14af5b2321b55 to your computer and use it in GitHub Desktop.
Save ben-bradley/340aeaa14af5b2321b55 to your computer and use it in GitHub Desktop.
Stream reply with Hapi
let valve = new Throtl.Valve({
limit: 20,
objectMode: true
});
reply(null, usersController
.readStream()
.pipe(valve)
.pipe(through.obj(function (user, enc, next) {
individualController
.readIndividual(user._id)
.then((individual) => {
user.foo = individual.foo;
let line = processUser(user);
this.push(line + '\n');
next();
})
.catch(debug);
}))
.pipe(through(function(line, enc, next) {
// this is necessary to convert the object stream to a regular stream
debug('line: ', line);
this.push(line);
next();
}))).type('text/plain');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment