use of io.reactivex.rxjava3.processors.ReplayProcessor in project redisson by redisson.
the class PublisherAdder method addAll.
public Single<Boolean> addAll(Publisher<? extends V> c) {
final Flowable<? extends V> cc = Flowable.fromPublisher(c);
final ReplayProcessor<Boolean> p = ReplayProcessor.create();
return p.doOnRequest(new LongConsumer() {
@Override
public void accept(long t) throws Exception {
final AtomicBoolean completed = new AtomicBoolean();
final AtomicLong values = new AtomicLong();
final AtomicBoolean lastSize = new AtomicBoolean();
cc.subscribe(new Consumer<V>() {
@Override
public void accept(V t) throws Exception {
values.getAndIncrement();
add(t).whenComplete((res, e) -> {
if (e != null) {
p.onError(e);
return;
}
if (res) {
lastSize.set(true);
}
if (values.decrementAndGet() == 0 && completed.get()) {
p.onNext(lastSize.get());
p.onComplete();
}
});
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
p.onError(t);
}
}, new Action() {
@Override
public void run() throws Exception {
completed.set(true);
if (values.get() == 0) {
p.onNext(lastSize.get());
p.onComplete();
}
}
});
}
}).singleOrError();
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project redisson by redisson.
the class RedissonKeysRx method createKeysIterator.
private Publisher<String> createKeysIterator(MasterSlaveEntry entry, String pattern, int count) {
ReplayProcessor<String> p = ReplayProcessor.create();
return p.doOnRequest(new LongConsumer() {
private RedisClient client;
private List<String> firstValues;
private long nextIterPos;
private long currentIndex;
@Override
public void accept(long value) {
currentIndex = value;
nextValues();
}
protected void nextValues() {
instance.scanIteratorAsync(client, entry, nextIterPos, pattern, count).whenComplete((res, e) -> {
if (e != null) {
p.onError(e);
return;
}
client = res.getRedisClient();
long prevIterPos = nextIterPos;
if (nextIterPos == 0 && firstValues == null) {
firstValues = (List<String>) (Object) res.getValues();
} else if (res.getValues().equals(firstValues)) {
p.onComplete();
currentIndex = 0;
return;
}
nextIterPos = res.getPos();
if (prevIterPos == nextIterPos) {
nextIterPos = -1;
}
for (Object val : res.getValues()) {
p.onNext((String) val);
currentIndex--;
if (currentIndex == 0) {
p.onComplete();
return;
}
}
if (nextIterPos == -1) {
p.onComplete();
currentIndex = 0;
}
if (currentIndex == 0) {
return;
}
nextValues();
});
}
});
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class SerializedProcessorTest method replaySubjectError.
@Test
public void replaySubjectError() {
ReplayProcessor<Integer> async = ReplayProcessor.create();
TestException te = new TestException();
async.onError(te);
FlowableProcessor<Integer> serial = async.toSerialized();
assertFalse(serial.hasSubscribers());
assertFalse(serial.hasComplete());
assertTrue(serial.hasThrowable());
assertSame(te, serial.getThrowable());
assertNull(async.getValue());
assertFalse(async.hasValue());
assertArrayEquals(new Object[] {}, async.getValues());
assertArrayEquals(new Integer[] {}, async.getValues(new Integer[0]));
assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 }));
assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 }));
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class SerializedProcessorTest method replaySubjectBoundedError.
@Test
public void replaySubjectBoundedError() {
ReplayProcessor<Integer> async = ReplayProcessor.createWithSize(1);
TestException te = new TestException();
async.onError(te);
FlowableProcessor<Integer> serial = async.toSerialized();
assertFalse(serial.hasSubscribers());
assertFalse(serial.hasComplete());
assertTrue(serial.hasThrowable());
assertSame(te, serial.getThrowable());
assertNull(async.getValue());
assertFalse(async.hasValue());
assertArrayEquals(new Object[] {}, async.getValues());
assertArrayEquals(new Integer[] {}, async.getValues(new Integer[0]));
assertArrayEquals(new Integer[] { null }, async.getValues(new Integer[] { 0 }));
assertArrayEquals(new Integer[] { null, 0 }, async.getValues(new Integer[] { 0, 0 }));
}
use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.
the class ReplayProcessorTest method sizeBoundZeroRequestError.
@Test
public void sizeBoundZeroRequestError() {
final ReplayProcessor<Integer> source = ReplayProcessor.createWithSize(16);
source.onError(new TestException());
source.test(0).assertFailure(TestException.class);
}
Aggregations