Conversation
src/index.ts
Outdated
| const array = [].slice.call(arrayValue); | ||
|
|
||
| while (!this._ended && consumerStreamReady && array.length > 0) { | ||
| consumerStreamReady = this.push(array.shift()); |
There was a problem hiding this comment.
I found in my benchmarking that calling shift() on a large array can be very slow. I opted for a for ... of with a conditional break statement instead.
|
Just a general thought, it might be nice to offer a similar convenience to native streams where you can either pass in a class MyThingy extends SplitArrayStream {
_getArray() {
// ... do stuff
}
}
// or
const myThingy = new SplitArrayStream({
getArray: () => { /* do stuff */ }
}); |
|
@callmehiphop there's a lot of new material for review in the last commit. The reason for all of the new complexity was:
I tried to solve these with a queue technique, that will push as many results as it can until the destination stream is exhausted. Then when the stream is ready for more, we push the new results to the end of the queue, and start to flush as many as we can. Please let me know if you see anything busted about this, but as with all things streams, it might take 6 days, 10 drinks, and a few calming nature hikes to fully figure out how this all works... but, I think it does work :) |
|
Yo @callmehiphop, whatcha think? |
This is a breaking change that will allow three types of uses, all with the new feature of backpressure automatically being applied.
Use 1, a source stream that emits arrays:
Use 2, a static array that needs to be split:
Use 3, a function that resolves with an array:
cc @callmehiphop