Why in this case do we need the Publish and RefCount Rx operators?

I'm trying to get acquainted with the problem of reactive backpressure processing, in particular by reading this wiki: https://github.com/ReactiveX/RxJava/wiki/Backpressure

In the buffer paragraph , we have this more attractive code example:

// we have to multicast the original bursty Observable so we can use it
// both as our source and as the source for our buffer closing selector:
Observable<Integer> burstyMulticast = bursty.publish().refCount();
// burstyDebounced will be our buffer closing selector:
Observable<Integer> burstyDebounced = burstMulticast.debounce(10, TimeUnit.MILLISECONDS);
// and this, finally, is the Observable of buffers we're interested in:
Observable<List<Integer>> burstyBuffered = burstyMulticast.buffer(burstyDebounced);

If I understand correctly, we are effectively debugging a discontinuous source stream, generating a debugged signal stream for the buffer operator.

But why do we need to use the publish and refcount operators? What problem would arise if we just dropped them? Comments don't make me clearer to me, aren't RxJava Observables up to multicast by default?

+4
1

.

2 , ( ). ( ), , 2 .

2 : , , , , , , .

, , . , 2 .

+ refcount/connect - , , , .

+3

Source: https://habr.com/ru/post/1610138/


All Articles