(no title)
esprehn | 3 days ago
Fwiw the original Streams API could have been simpler even without async iterators.
interface Stream<T> {
// Return false from the callback to stop early.
// Result is if the stream was completed.
forEach(callback: (chunk: T) => Promise<boolean | undefined>): Promise<boolean>
}
Similarly adding a recycleBuffer(chunk) method would have gone a long way towards BYOB without all the ceremony.If we're optimizing allocations we can also avoid all the {done,value} records and return a semaphore value for the end in the proposed API.
(Web) API design is really difficult and without a voice in the room pushing really hard on ergonomics and simplicity it's easy to solve all the use cases but end up with lots of awkward corners and costs later.
No comments yet.