4 ms·
This is exactly why data patterns like Observables (https://github.com/tc39/proposal-observable https://github.com/tc39/proposal-observable) and ReactiveX (http
by jadbox 5y ago
This is exactly why data patterns like Observables (https://github.com/tc39/proposal-observable https://github.com/tc39/proposal-observable) and ReactiveX (http://reactivex.io/ http://reactivex.io/) are so powerful. You can design your interface to be subjective to both. :)
- btown 5y agoIt's a bit more complicated than this, because Observables in both frameworks are only required to implement push-style interfaces (that's the public interface of event listeners by design), and if a consumer wishes to pull at its own rate from an arbitrary source, the only general solution is to create an infinite buffer that materializes the pusher's outputs, which is the exact performance tradeoff described in the (excellent) OP article. http://reactivex.io/documentation/operators/backpressure.html http://reactivex.io/documentation/operators/backpressure.htm... describes ReactiveX's approach to the problem in great detail. To quote the section that essentially reaches the same conclusion as the grandparent post pointing out how "forks" (using the same pull-style data source twice) inherently require buffering/materialization or sampling: > When a cold Observable is multicast (when it is converted into a connectable Observable and its Connect method is called), it effectively becomes hot and for the purposes of backpressure and flow-control it should be treated as a hot Observable. Cold Observables are ideal for the reactive pull model of backpressure implemented by some implementations of ReactiveX (which is described elsewhere). Hot Observables typically do not cope well with a reactive pull model, and are better candidates for other flow control strategies, such as the use of the operators described on this page, or operators like Buffer, Sample, Debounce, or Window. There are great visuals if you expand the RxJS examples in the link above.