3 ms·
The addons in the newer RxJava version where the the consumer can request a number of items and the producer might not overflow the window makes that better. Th
by Matthias247 10y ago
The addons in the newer RxJava version where the the consumer can request a number of items and the producer might not overflow the window makes that better. The same model is also used in reactive streams.
But I would agree Rx is not the best possible model for streams with backpressure. Besides signaling for backpressure I also have the concern that many operators don't have support for backpressure, automatic backpressure to multiple consumers is hairy and that the push based system is also a lot more prone to resource (or information) leaks - because the producer might push something into a buffer which is never read by anyone if the consumers cancel the stream.
I still think Rx is a great tool for some use cases (e.g. inside UIs for reacting to button presses, state changes, etc.) and I'm currently using it a lot in angular2 to connect between information providers and widgets.
But for lower level data streams with backpressure between single sources and sinks, distributing resources and data exchange between multiple threads I'm now favoring other approaches.
I've experimented with a lot of designs over the last years and in the meantime I favor pull based approaches (like Future<T> getNextItem() or in Go simply read(buffer) methods there. I get backpressure naturally if I only invoke a new read after the last one has finished, I can even reuse a single buffer for all reads and composition also works through normal functions. Drawback might be throughput, but on bottlenecks one can still introduce a buffer.
Node seems to favor it's own stream implementation (ReadableStream and WriteableStream instead of Rx, which is especially designed for this use-cases, but it's dual nature (switch between push and pull based) can make it hard to understand in some situations. The whatwg streams approach could be promising, but doesn't seem to be fully specified yet.