use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheTimeTest method partialCancelDoesntCancelSource.
@Test
public void partialCancelDoesntCancelSource() {
AtomicInteger cancelled = new AtomicInteger();
Mono<Object> cached = Mono.never().doOnCancel(cancelled::incrementAndGet).cache(Duration.ofMillis(200));
Disposable d1 = cached.subscribe();
Disposable d2 = cached.subscribe();
d1.dispose();
assertThat(cancelled).hasValue(0);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class MonoCacheTimeTest method noTtlCancelDoesntCancelSource.
@Test
public void noTtlCancelDoesntCancelSource() {
AtomicInteger cancelled = new AtomicInteger();
Mono<Object> cached = new MonoCacheTime<>(Mono.never().doOnCancel(cancelled::incrementAndGet));
Disposable d1 = cached.subscribe();
Disposable d2 = cached.subscribe();
d1.dispose();
assertThat(cancelled.get()).as("when cancelling d1").isEqualTo(0);
d2.dispose();
assertThat(cancelled.get()).as("when both cancelled").isEqualTo(0);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class FluxRefCount method cancel.
void cancel(RefCountMonitor rc) {
Disposable dispose = null;
synchronized (this) {
if (rc.terminated) {
return;
}
long c = rc.subscribers - 1;
rc.subscribers = c;
if (c != 0L || !rc.connected) {
return;
}
if (rc == connection) {
dispose = RefCountMonitor.DISCONNECT.getAndSet(rc, Disposables.disposed());
connection = null;
}
}
if (dispose != null) {
dispose.dispose();
}
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class BaseSubscriberTest method disposeCancels.
@Test
public void disposeCancels() throws InterruptedException {
AtomicReference<SignalType> onFinally = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
BaseSubscriber<Long> sub = new BaseSubscriber<Long>() {
@Override
protected void hookOnSubscribe(Subscription subscription) {
requestUnbounded();
}
@Override
protected void hookOnNext(Long value) {
fail("delay was not cancelled");
}
@Override
protected void hookFinally(SignalType type) {
onFinally.set(type);
latch.countDown();
}
};
Disposable d = Mono.delay(Duration.ofSeconds(1)).subscribeWith(sub);
d.dispose();
assertThat(latch.await(1500, TimeUnit.MILLISECONDS)).as("delay should be skipped by cancel").isTrue();
assertThat(onFinally).hasValue(SignalType.CANCEL);
}
use of reactor.core.Disposable in project reactor-core by reactor.
the class BoundedElasticScheduler method schedulePeriodically.
@Override
public Disposable schedulePeriodically(Runnable task, long initialDelay, long period, TimeUnit unit) {
final BoundedState picked = BOUNDED_SERVICES.get(this).pick();
Disposable scheduledTask = Schedulers.directSchedulePeriodically(picked.executor, task, initialDelay, period, unit);
// (ie decreases its usage by one)
return Disposables.composite(scheduledTask, picked);
}
Aggregations