Created
August 11, 2015 18:44
-
-
Save ben-bradley/340aeaa14af5b2321b55 to your computer and use it in GitHub Desktop.
Stream reply with Hapi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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