Created
August 23, 2017 12:15
-
-
Save pokle/a5996c62b5ba125a467ce049ccdff537 to your computer and use it in GitHub Desktop.
nodejs neeson template with back pressure
This file contains 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
// Try this with: seq 1 10 | node ndjson.js | |
// Don't forget to npm install ndjson | |
const ndjson = require('ndjson') | |
const parser = ndjson.parse(); | |
const printer = ndjson.serialize(); | |
printer.pipe(process.stdout); | |
process.stdin | |
.pipe(parser) | |
.on('data', function(obj) { | |
console.error('GOT', obj) | |
parser.pause(); | |
setTimeout(() => { | |
printer.write({...obj, processed: true}); | |
parser.resume(); | |
}, 1000); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment