Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: added backpressure to the add stream (#810)
Browse files Browse the repository at this point in the history
* fix: added backpressure to the add stream
  • Loading branch information
pgte authored and daviddias committed Mar 27, 2017
1 parent 74b2b70 commit 31dbabc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ class AddStreamDuplex extends Duplex {
super(Object.assign({ objectMode: true }, options))
this._pullStream = pullStream
this._pushable = push
this._waitingPullFlush = []
}

_read () {
this._pullStream(null, (end, data) => {
while (this._waitingPullFlush.length) {
const cb = this._waitingPullFlush.shift()
cb()
}
if (end) {
if (end instanceof Error) {
this.emit('error', end)
Expand All @@ -199,7 +204,7 @@ class AddStreamDuplex extends Duplex {
}

_write (chunk, encoding, callback) {
this._waitingPullFlush.push(callback)
this._pushable.push(chunk)
callback()
}
}

0 comments on commit 31dbabc

Please sign in to comment.