Add `fromHandlers` for easier broadcast streams (dart-lang/stream_transform#21)
Fixes dart-lang/stream_transform#18
StreamTransformer.fromHandlers constructor does not behave as expected
for broadcast streams - handlers are called once per listener rather
than once per event. This means that closures which share state for a
single source stream won't work correctly for broadcast streams with
multiple listeners. The transformers currently using this pattern are
most readable with it vs a custom StreamTransformer class for each one,
so add a `fromHandlers` utility which mimics that constructor but only
calls the handlers once per event and the broadcast multiplexing is done
on the other side.
- Add _StreamTransformers with an overridable handleData and handleDone.
Eventually handleError will be needed, but this is all that is
required to solve the bug with `debounce`.
- Add tests for _StreamTransformers across both single-subscrption and
broadcast streams. All these tests pass with either `new
StreamTransformers.fromhandlers` or the new `fromhandlers` except the
'called once' tests.
- Add a pair of tests for debounce and debounceBuffer which exhibit the
bug - data is only added to one of the listeners because the Timer is
overridden to the last listener whose handleData is called.
- Update debounce to use `fromHandlers` and see that the tests pass.
Other StreamTransformers in this package have the same bug and will be
fixed in subsequent commits.
6 files changed
tree: 66e06da3f92e93014fdfccb54812d2e7bbb0e3c2
- pkgs/