{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/help/issues/2088","repository_url":"https://api.github.com/repos/nodejs/help","labels_url":"https://api.github.com/repos/nodejs/help/issues/2088/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/help/issues/2088/comments","events_url":"https://api.github.com/repos/nodejs/help/issues/2088/events","html_url":"https://github.com/nodejs/help/issues/2088","id":474994809,"node_id":"MDU6SXNzdWU0NzQ5OTQ4MDk=","number":2088,"title":"process.stdin.on('data') fires all it's data in the same tick","user":{"login":"ORESoftware","id":11139560,"node_id":"MDQ6VXNlcjExMTM5NTYw","avatar_url":"https://avatars1.githubusercontent.com/u/11139560?v=4","gravatar_id":"","url":"https://api.github.com/users/ORESoftware","html_url":"https://github.com/ORESoftware","followers_url":"https://api.github.com/users/ORESoftware/followers","following_url":"https://api.github.com/users/ORESoftware/following{/other_user}","gists_url":"https://api.github.com/users/ORESoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/ORESoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ORESoftware/subscriptions","organizations_url":"https://api.github.com/users/ORESoftware/orgs","repos_url":"https://api.github.com/users/ORESoftware/repos","events_url":"https://api.github.com/users/ORESoftware/events{/privacy}","received_events_url":"https://api.github.com/users/ORESoftware/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2019-07-31T08:02:03Z","updated_at":"2019-07-31T20:53:13Z","closed_at":null,"author_association":"NONE","body":"I ran this:\r\n\r\n```bash\r\ntail -n 35111  <file> | node read-stdin.js\r\n```\r\n\r\nin `read-stdin.js` I have:\r\n\r\n```js\r\nprocess.stdin.resume().on('data', d =>{\r\n  console.log(d);\r\n});\r\n```\r\n\r\nwhat seems to happen is that all the on('data') calls happen in the same tick - so I can't have any user interaction with the script (signals etc), until all the data events fire. Is this expected? Any way around this?\r\n\r\nI thought about adding some buffer process:\r\n\r\n```bash\r\ntail -n 35111  <file> | buffer | node read-stdin.js\r\n```\r\n\r\nbut I don't really know how to delay things so that the nodejs receiver can handle other i/o in the meantime.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/help/issues/comments/517016737","html_url":"https://github.com/nodejs/help/issues/2088#issuecomment-517016737","issue_url":"https://api.github.com/repos/nodejs/help/issues/2088","id":517016737,"node_id":"MDEyOklzc3VlQ29tbWVudDUxNzAxNjczNw==","user":{"login":"addaleax","id":899444,"node_id":"MDQ6VXNlcjg5OTQ0NA==","avatar_url":"https://avatars2.githubusercontent.com/u/899444?v=4","gravatar_id":"","url":"https://api.github.com/users/addaleax","html_url":"https://github.com/addaleax","followers_url":"https://api.github.com/users/addaleax/followers","following_url":"https://api.github.com/users/addaleax/following{/other_user}","gists_url":"https://api.github.com/users/addaleax/gists{/gist_id}","starred_url":"https://api.github.com/users/addaleax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/addaleax/subscriptions","organizations_url":"https://api.github.com/users/addaleax/orgs","repos_url":"https://api.github.com/users/addaleax/repos","events_url":"https://api.github.com/users/addaleax/events{/privacy}","received_events_url":"https://api.github.com/users/addaleax/received_events","type":"User","site_admin":false},"created_at":"2019-07-31T20:53:13Z","updated_at":"2019-07-31T20:53:13Z","author_association":"MEMBER","body":"> well my guess was that applying backpressure would force the reader to wait til next tick to read etc, but maybe that's wrong\r\n\r\nNot applying backpressure is generally a bug, but it may or may not be what helps here and that’s impossible to tell without knowing your application better. If the data processing happens synchronously, it won’t help. If it happens asynchronously, it will help, and it will force data to be emitted in a later event loop turn.\r\n\r\nIf delaying to the next event loop turn is really all you need, then this will help:\r\n\r\n```js\r\nconst delayTransform = new Transform({\r\n  transform(chunk, enc, cb) {\r\n    // Artificially delay passing on the data by one event loop turn\r\n    setImmediate(cb, null, chunk);\r\n  }\r\n});\r\n\r\nprocess.stdin.pipe(delayTransform).on('data', ...)\r\n```"}}
{"actor":{"display_login":"addaleax"}}