use of io.servicetalk.concurrent.internal.DelayedCancellable in project servicetalk by apple.
the class AbstractSubmitCompletable method handleSubscribe.
@Override
protected final void handleSubscribe(final CompletableSource.Subscriber subscriber) {
DelayedCancellable cancellable = new DelayedCancellable();
subscriber.onSubscribe(cancellable);
final Cancellable eCancellable;
try {
eCancellable = runExecutor.execute(() -> {
try {
runnable().run();
} catch (Throwable cause) {
subscriber.onError(cause);
return;
}
subscriber.onComplete();
});
} catch (Throwable cause) {
// We assume that runExecutor.execute() either throws or executes the Runnable. Hence we do not have to
// protect against duplicate terminal events.
subscriber.onError(cause);
return;
}
cancellable.delayedCancellable(eCancellable);
}
use of io.servicetalk.concurrent.internal.DelayedCancellable in project servicetalk by apple.
the class CompletableProcessor method handleSubscribe.
@Override
protected void handleSubscribe(Subscriber subscriber) {
// We must subscribe before adding subscriber the the queue. Otherwise it is possible that this
// Completable has been terminated and the subscriber may be notified before onSubscribe is called.
// We used a DelayedCancellable to avoid the case where the Subscriber will synchronously cancel and then
// we would add the subscriber to the queue and possibly never (until termination) dereference the subscriber.
DelayedCancellable delayedCancellable = new DelayedCancellable();
subscriber.onSubscribe(delayedCancellable);
if (stack.push(subscriber)) {
delayedCancellable.delayedCancellable(() -> {
// Cancel in this case will just cleanup references from the queue to ensure we don't prevent GC of
// these references.
stack.relaxedRemove(subscriber);
});
}
}
use of io.servicetalk.concurrent.internal.DelayedCancellable in project servicetalk by apple.
the class AutoOnSubscribeCompletableSubscriberFunction method apply.
@Override
public Subscriber apply(final Subscriber subscriber) {
final DelayedCancellable subscription = new DelayedCancellable();
subscriber.onSubscribe(subscription);
return new DelegatingCompletableSubscriber(subscriber) {
@Override
public void onSubscribe(final Cancellable s) {
subscription.delayedCancellable(s);
}
};
}
use of io.servicetalk.concurrent.internal.DelayedCancellable in project servicetalk by apple.
the class TimerCompletable method handleSubscribe.
@Override
protected void handleSubscribe(final Subscriber subscriber) {
DelayedCancellable cancellable = new DelayedCancellable();
subscriber.onSubscribe(cancellable);
try {
cancellable.delayedCancellable(timeoutExecutor.schedule(subscriber::onComplete, delayNs, NANOSECONDS));
} catch (Throwable cause) {
subscriber.onError(cause);
}
}
use of io.servicetalk.concurrent.internal.DelayedCancellable in project servicetalk by apple.
the class SingleProcessor method handleSubscribe.
@Override
protected void handleSubscribe(final Subscriber<? super T> subscriber) {
// We must subscribe before adding subscriber the the queue. Otherwise it is possible that this
// Single has been terminated and the subscriber may be notified before onSubscribe is called.
// We used a DelayedCancellable to avoid the case where the Subscriber will synchronously cancel and then
// we would add the subscriber to the queue and possibly never (until termination) dereference the subscriber.
DelayedCancellable delayedCancellable = new DelayedCancellable();
subscriber.onSubscribe(delayedCancellable);
if (stack.push(subscriber)) {
delayedCancellable.delayedCancellable(() -> {
// Cancel in this case will just cleanup references from the queue to ensure we don't prevent GC of
// these references.
stack.relaxedRemove(subscriber);
});
}
}
Aggregations