streams
streams copied to clipboard
Define valid queuing strategy
As an author- and other-spec-facing requirement, we should define valid queuing strategies. I think the requirements are:
- have size() methods and highWaterMark properties.
- size() is pure (gives the same result for the same input every time)
- size() never returns NaN, +Infinity, or negative
- highWaterMark is not NaN and not < 0
- (maybe) highWaterMark does not change over time?
- (maybe) size never throws an exception?
- Can highWaterMark be 0? (what could be the use cases?)
- Can highWaterMark be a float?
A related question: Why does a queuing strategy get an object as argument and not simply a value (new CountQueingStrategy({ highWaterMark: 42 })
against new CountQueingStrategy(42)
)?
Also, I think the constructor should raise a TypeError if given a bad highWaterMark value.
I think highWaterMark
should be updatable since it might be useful for an AdaptiveQueuingStrategy
.
Can highWaterMark be 0? (what could be the use cases?)
Yes. For example, for a writable stream, this would apply backpressure whenever there is a write pending.
Can highWaterMark be a float?
Sure.
A related question: Why does a queuing strategy get an object as argument and not simply a value
This allows better future extensibility and explicitness in the code. It's a bit of a judgment call, but that's where we ended up.
Also, I think the constructor should raise a TypeError if given a bad highWaterMark value.
I think it's OK since it's validated at stream construction time. It's nice that the queueing strategy classes are just dumb value holders, IMO. It's their consumers who have notions of how they should act.
I think highWaterMark should be updatable since it might be useful for an AdaptiveQueuingStrategy.
This is actually impossible now due to how we copy the properties in the constructor :-/.
- size() does nothing for byte streams. Related: #729
- highWaterMark is copied so there's no way to make it change over time
- I think size() has to throw for invalid types. For example
size(chunk) { return chunk.length; }
.
Regarding highWaterMark, I think we could instead explore making [[strategyHWM]]
adjustable.