-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define how "push" interacts with highWaterMark on readable side (suspending of push) #12
Comments
The existing API already provides for this (although I admit I don't have an example of using it yet). If In other words, I do not understand what this proposal offers over the API in the readme. I also don't understand if you are abandoning the idea of |
Re-reading the readme I am mistaken about the constructor... As I understand it from reading it again the function passed to the constructor After reading the various long threads about promises the first thing I think is this thing will only be called once. To be clear then // (but with ES6 and extending ReadableStream)
function MyReader() {
ReadableStream.call(this);
}
MyReader.prototype.onRead = function(push, done, error) {} Assuming the above is true why do we need the function on the constructor? |
onRead is not a method of streams; it is a function you pass to a stream constructor to tell it how it that stream reacts to read calls. A sample implementation might be something like: class ReadableStream {
constructor(options, onRead) {
this._options = options;
this._onRead = onRead;
this._internalBuffer = new ArrayBuffer(options.highWaterMark);
}
read() {
this._onRead(data => {
pushInto(this._internalBuffer, data);
return !hasRoomLeft(this._internalBuffer, this._options);
}, ...);
process.nextTick(() => this._internalBuffer = new ArrayBuffer(options.highWaterMark);
if (hasData(this._internalBuffer)) {
return Promise.resolve(this._internalBuffer);
}
return waitForData(this._internalBuffer).then(() => this._internalBuffer);
}
} |
The new |
Node's internal use of highWaterMark is mostly in conjunction with the ability to call an explicit method to read with an explicit number number of bytes triggered by a request for data.
To have sane piping I believe we need the ability to halt the flow of data on the readable side (if the writer is blocked we can attempt to pause the reader). This is where having some enforced convention seems useful:
My theoretical example of how this might work:
In the case where the promise is ignored (we should also set a flag?) then report it somehow?
The text was updated successfully, but these errors were encountered: