-
-
Save max-mapper/b0bafdc6b9d8510124dd to your computer and use it in GitHub Desktop.
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
> echo '{"a":1}' | ../node_query_server/bin/qs2 | |
net.js:614 | |
throw new TypeError('invalid data'); | |
^ | |
TypeError: invalid data | |
at WriteStream.Socket.write (net.js:614:11) | |
at null._onTimeout (/Users/jan/Work/qs2/node_query_server/index.js:17:20) | |
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) |
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
var ndj = require('ndjson'); | |
var through = require('through2') | |
process.stdin.setEncoding('utf8'); | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
var send = through.obj(function(data, enc, done) { | |
// console.error('data: ', data); | |
setTimeout(function() { | |
send.write(data); | |
done() | |
}, getRandomInt(1, 100)); | |
}; | |
process | |
.stdin | |
.pipe(ndj.parse()) | |
.pipe(send) | |
.pipe(ndj.serialize()) | |
.pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NEAT!
Doesn’t seem quite right, though: