Add trailing argument to throttle (dart-lang/stream_transform#123)

Closes dart-lang/stream_transform#122

The existing rate limit utilities don't cover the case of wanting to
update a UI with some changing data with a limited frequency. In this
case the goal is to get the "latest" event with minimal lag time, while
maintaining at least a given duration in between events. Add a
`trailing` argument to `throttle` for an operator which will emit
immediately when possible (unlike `audit`), and does not get starved by a
long series of frequent events (unlike `debounce`).

Expand the doc with the same timeline diagrams as used for other
operators.

Split the implementation into two methods to avoid extra conditional
checks and unused variables for the common case of `trailing: false`.
Add tests for the behavior of emitting the trailing event, suppressing
intermediate events, and keeping the stream open until the final
trailing even is emitted.
3 files changed
tree: 3ae123908178d24f6d61fcf5affb63a1221aef6e
  1. pkgs/