{"action":"created","issue":{"url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/issues/4","repository_url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream","labels_url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/issues/4/comments","events_url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/issues/4/events","html_url":"https://github.com/pull-stream/pull-stream-to-stream/pull/4","id":174552159,"number":4,"title":"fix needDrain emitting to match the amount of pauses","user":{"login":"dignifiedquire","id":790842,"avatar_url":"https://avatars.githubusercontent.com/u/790842?v=3","gravatar_id":"","url":"https://api.github.com/users/dignifiedquire","html_url":"https://github.com/dignifiedquire","followers_url":"https://api.github.com/users/dignifiedquire/followers","following_url":"https://api.github.com/users/dignifiedquire/following{/other_user}","gists_url":"https://api.github.com/users/dignifiedquire/gists{/gist_id}","starred_url":"https://api.github.com/users/dignifiedquire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dignifiedquire/subscriptions","organizations_url":"https://api.github.com/users/dignifiedquire/orgs","repos_url":"https://api.github.com/users/dignifiedquire/repos","events_url":"https://api.github.com/users/dignifiedquire/events{/privacy}","received_events_url":"https://api.github.com/users/dignifiedquire/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-01T15:20:37Z","updated_at":"2016-09-02T12:24:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/pulls/4","html_url":"https://github.com/pull-stream/pull-stream-to-stream/pull/4","diff_url":"https://github.com/pull-stream/pull-stream-to-stream/pull/4.diff","patch_url":"https://github.com/pull-stream/pull-stream-to-stream/pull/4.patch"},"body":"Trying to work out a test for this, which I will hopefully push soon"},"comment":{"url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/issues/comments/244360293","html_url":"https://github.com/pull-stream/pull-stream-to-stream/pull/4#issuecomment-244360293","issue_url":"https://api.github.com/repos/pull-stream/pull-stream-to-stream/issues/4","id":244360293,"user":{"login":"dignifiedquire","id":790842,"avatar_url":"https://avatars.githubusercontent.com/u/790842?v=3","gravatar_id":"","url":"https://api.github.com/users/dignifiedquire","html_url":"https://github.com/dignifiedquire","followers_url":"https://api.github.com/users/dignifiedquire/followers","following_url":"https://api.github.com/users/dignifiedquire/following{/other_user}","gists_url":"https://api.github.com/users/dignifiedquire/gists{/gist_id}","starred_url":"https://api.github.com/users/dignifiedquire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dignifiedquire/subscriptions","organizations_url":"https://api.github.com/users/dignifiedquire/orgs","repos_url":"https://api.github.com/users/dignifiedquire/repos","events_url":"https://api.github.com/users/dignifiedquire/events{/privacy}","received_events_url":"https://api.github.com/users/dignifiedquire/received_events","type":"User","site_admin":false},"created_at":"2016-09-02T12:24:22Z","updated_at":"2016-09-02T12:24:22Z","body":"> it would help if you describe the problem? it's harder to interpret code than text\r\n\r\nOf course. \r\n\r\nGiven a src readable stream and a dest writable stream, which are `src.pipe(dest)` together, the following happens\r\n\r\n- If src receives `false` from a `write` call it moves into a paused state, increasing an awaitDrain counter and `pause` itself. (https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L555-L568)\r\n- Once `'drain'` is emitted from dest, it will check the awaitDrain counter, and decrement it. If it is at `0` it will resume it self. (https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L619-L623)\r\n- On **every** `'data'` event from src it tries to call `write` on dest, independent of the state of src. (https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L551-L552)\r\n\r\nThe above behaviour results in what you mentioned of pausing multiple times one after another, without `'drain'` in between. Because there is a counter, which checks how often writes returned `false`, dest needs to emit the exact same amount of `'drain'` events to makes src return into flowing mode. \r\n\r\nWith the current code where I put the `needDrain = false` into the `nextTick` call, this does not happen, as those `write() === false` calls in between are not tracked properly. \r\n\r\nThe best solution I could come up with was to move the `needDrain = false` out, such that it is process synchronously, triggering in the next round a new `'drain'` event, corresponding to the write call that returned false. \r\n\r\n\r\n"}}
{"actor":{"display_login":"dignifiedquire"}}