java.lang.Object
com.github.mizosoft.methanol.internal.flow.AbstractSubscription<T>
- All Implemented Interfaces:
Flow.Subscription
- Direct Known Subclasses:
AbstractPollableSubscription
An abstract
Flow.Subscription
that implements most of the machinery for execution and
backpressure control.-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractSubscription
(Flow.Subscriber<? super T> downstream, Executor executor) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
abort
(boolean flowInterrupted) Releases resources held by this subscription.final void
cancel()
protected final void
cancelOnComplete
(Flow.Subscriber<? super T> downstream) Calls downstream'sonComplete
after cancelling this subscription.protected final void
cancelOnError
(Flow.Subscriber<? super T> downstream, Throwable exception, boolean flowInterrupted) Calls downstream'sonError
with the given exception after cancelling this subscription.protected long
protected abstract long
emit
(Flow.Subscriber<? super T> downstream, long emit) Emits at mostemit
items to downstream usingsubmitOnNext(Subscriber, Object)
as long as it returnstrue
.void
void
fireOrKeepAliveOnError
(Throwable exception) void
protected final boolean
Returnstrue
if the subscriber is to be completed exceptionally.protected final boolean
Returnstrue
if this subscription is cancelled.final void
request
(long n) protected final boolean
submitOnNext
(Flow.Subscriber<? super T> downstream, T item) Submits given item to the downstream, returningfalse
and cancelling on failure.
-
Constructor Details
-
AbstractSubscription
-
-
Method Details
-
request
public final void request(long n) - Specified by:
request
in interfaceFlow.Subscription
-
cancel
public final void cancel()- Specified by:
cancel
in interfaceFlow.Subscription
-
fireOrKeepAlive
public void fireOrKeepAlive() -
fireOrKeepAliveOnNext
public void fireOrKeepAliveOnNext() -
fireOrKeepAliveOnError
-
emit
Emits at mostemit
items to downstream usingsubmitOnNext(Subscriber, Object)
as long as it returnstrue
. The actual number of emitted items is returned, may be 0 in case of cancellation or if no items are emitted, perhaps due to lack thereof, or ifemit
itself is zero. If the underlying source is finished, the subscriber is completed withcancelOnComplete(Subscriber)
. -
abort
protected void abort(boolean flowInterrupted) Releases resources held by this subscription.flowInterrupted
tells whether cancellation was due to flow interruption by downstream (e.g. callingcancel()
or throwing fromonNext
oronSubscribe
), or due to ending the normal flow of signals (onSubscribe -> onNext* -> (onError | onComplete)). -
isCancelled
protected final boolean isCancelled()Returnstrue
if this subscription is cancelled.false
result is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously cancelled. -
hasPendingErrors
protected final boolean hasPendingErrors()Returnstrue
if the subscriber is to be completed exceptionally.false
result is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously signalled with an error. -
cancelOnError
protected final void cancelOnError(Flow.Subscriber<? super T> downstream, Throwable exception, boolean flowInterrupted) Calls downstream'sonError
with the given exception after cancelling this subscription.flowInterrupted
tells whether the error interrupted the normal flow of signals. -
cancelOnComplete
Calls downstream'sonComplete
after cancelling this subscription. -
submitOnNext
Submits given item to the downstream, returningfalse
and cancelling on failure.false
is also returned if the subscription is already cancelled or has pending errors. On such cases, caller should stop emitting items. -
currentDemand
protected long currentDemand()
-