repeaterjs / repeater

The missing constructor for creating safe async iterators
https://repeater.js.org
MIT License
459 stars 12 forks source link

Make throw throw when push is unhandled. #43

Closed brainkim closed 4 years ago

brainkim commented 4 years ago

A second attempt at resolving #35. I finally managed to get unhandled pushes to throw when repeater.throw is called by chaining promises in push rather than next/return/throw. The push function is the only place where we have access to both the promise passed to push and the promise returned from push in sequence.

One consequence of this refactoring is that we always pass promises to the push queue and buffer rather than naked values. Therefore, this PR also removes the type parameter of RepeaterBuffer and makes the parameter type of buffer.add and the return type of buffer.remove both unknown. This is beneficial in that it prevents inferring the type of the repeater from the type of its buffer, and makes it slightly harder for typescript users to add or remove values from repeater buffers. Adding or removing values from the repeater’s buffer is not and should not be supported and adding this unknown hitch is the best way to do this that doesn’t involve drastic checks to make sure only repeaters call buffer.add and buffer.remove.

This PR also does a big, dirty clean-up of the test suite.