use of io.reactivex.rxjava3.functions.Action 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.functions.Action in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method directSchedulePeriodicallyUsesHookOnce.
@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyUsesHookOnce() {
final CountingRunnable newCounter = new CountingRunnable();
final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
@Override
public Runnable apply(Runnable runnable) {
runnableRef.set(runnable);
return newCounter;
}
});
CountingRunnable counter = new CountingRunnable();
scheduler.schedulePeriodicallyDirect(counter, 1, 1, MINUTES);
// Verify our action was passed to the schedulers hook.
assertSame(counter, runnableRef.get());
runnableRef.set(null);
idleMainLooper(1, MINUTES);
runUiThreadTasks();
// Verify the scheduled action was the one returned from the hook.
assertEquals(1, newCounter.get());
assertEquals(0, counter.get());
// Ensure the hook was not called again when the runnable re-scheduled itself.
assertNull(runnableRef.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method throwingActionRoutedToRxJavaPlugins.
@Test
public void throwingActionRoutedToRxJavaPlugins() {
Consumer<? super Throwable> originalErrorHandler = RxJavaPlugins.getErrorHandler();
try {
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwableRef.set(throwable);
}
});
Worker worker = scheduler.createWorker();
final NullPointerException npe = new NullPointerException();
Runnable action = new Runnable() {
@Override
public void run() {
throw npe;
}
};
worker.schedule(action);
runUiThreadTasks();
assertSame(npe, throwableRef.get());
} finally {
RxJavaPlugins.setErrorHandler(originalErrorHandler);
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableConsumersTest method onCompleteCrash.
@Test
public void onCompleteCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
processor.subscribe(new Action() {
@Override
public void run() throws Exception {
throw new IOException();
}
}, this, composite);
processor.onComplete();
assertTrue(events.toString(), events.isEmpty());
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class MaybeDoOnTerminateTest method doOnTerminateSuccess.
@Test
public void doOnTerminateSuccess() {
final AtomicBoolean atomicBoolean = new AtomicBoolean();
Maybe.just(1).doOnTerminate(new Action() {
@Override
public void run() {
atomicBoolean.set(true);
}
}).test().assertResult(1);
assertTrue(atomicBoolean.get());
}
Aggregations