use of io.reactivex.rxjava3.processors.ReplayProcessor in project redisson by redisson.
the class RedissonTopicRx method getMessages.
public <M> Flowable<M> getMessages(Class<M> type) {
ReplayProcessor<M> p = ReplayProcessor.create();
return p.doOnRequest(new LongConsumer() {
@Override
public void accept(long n) throws Exception {
AtomicLong counter = new AtomicLong(n);
RFuture<Integer> t = topic.addListenerAsync(type, new MessageListener<M>() {
@Override
public void onMessage(CharSequence channel, M msg) {
p.onNext(msg);
if (counter.decrementAndGet() == 0) {
topic.removeListenerAsync(this);
p.onComplete();
}
}
});
t.whenComplete((id, e) -> {
if (e != null) {
p.onError(e);
return;
}
p.doOnCancel(new Action() {
@Override
public void run() throws Exception {
topic.removeListenerAsync(id);
}
});
});
}
});
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class ReplayProcessorTest method peekStateTimeAndSizeValue.
@Test
public void peekStateTimeAndSizeValue() {
ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.computation(), 1);
assertNull(rp.getValue());
assertEquals(0, rp.getValues().length);
assertNull(rp.getValues(new Integer[2])[0]);
rp.onComplete();
assertNull(rp.getValue());
assertEquals(0, rp.getValues().length);
assertNull(rp.getValues(new Integer[2])[0]);
rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.computation(), 1);
rp.onError(new TestException());
assertNull(rp.getValue());
assertEquals(0, rp.getValues().length);
assertNull(rp.getValues(new Integer[2])[0]);
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class ReplayProcessorTest method subscriptionLeak.
@Test
public void subscriptionLeak() {
ReplayProcessor<Object> replaySubject = ReplayProcessor.create();
Disposable connection = replaySubject.subscribe();
assertEquals(1, replaySubject.subscriberCount());
connection.dispose();
assertEquals(0, replaySubject.subscriberCount());
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class ReplayProcessorTest method sizeAndHasAnyValueUnboundedEmptyError.
@Test
public void sizeAndHasAnyValueUnboundedEmptyError() {
ReplayProcessor<Object> rs = ReplayProcessor.create();
rs.onError(new TestException());
assertEquals(0, rs.size());
assertFalse(rs.hasValue());
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class ReplayProcessorTest method unboundedZeroRequestError.
@Test
public void unboundedZeroRequestError() {
final ReplayProcessor<Integer> source = ReplayProcessor.create();
source.onError(new TestException());
source.test(0).assertFailure(TestException.class);
}
Aggregations