Class AbstractSubscription<T>
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
ConstructorsModifierConstructorDescriptionprotectedAbstractSubscription(Flow.Subscriber<? super T> downstream, Executor executor) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidabort(boolean flowInterrupted) Releases resources held by this subscription.final voidcancel()protected final voidcancelOnComplete(Flow.Subscriber<? super T> downstream) Calls downstream'sonCompleteafter cancelling this subscription.protected final voidcancelOnError(Flow.Subscriber<? super T> downstream, Throwable exception, boolean flowInterrupted) Calls downstream'sonErrorwith the given exception after cancelling this subscription.protected longprotected abstract longemit(Flow.Subscriber<? super T> downstream, long emit) Emits at mostemititems to downstream usingsubmitOnNext(Subscriber, Object)as long as it returnstrue.voidvoidfireOrKeepAliveOnError(Throwable exception) voidprotected final booleanReturnstrueif the subscriber is to be completed exceptionally.protected final booleanReturnstrueif this subscription is cancelled.final voidrequest(long n) protected final booleansubmitOnNext(Flow.Subscriber<? super T> downstream, T item) Submits given item to the downstream, returningfalseand cancelling on failure.
-
Constructor Details
-
AbstractSubscription
-
-
Method Details
-
request
public final void request(long n) - Specified by:
requestin interfaceFlow.Subscription
-
cancel
public final void cancel()- Specified by:
cancelin interfaceFlow.Subscription
-
fireOrKeepAlive
public void fireOrKeepAlive() -
fireOrKeepAliveOnNext
public void fireOrKeepAliveOnNext() -
fireOrKeepAliveOnError
-
emit
Emits at mostemititems 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 ifemititself 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.flowInterruptedtells whether cancellation was due to flow interruption by downstream (e.g. callingcancel()or throwing fromonNextoronSubscribe), or due to ending the normal flow of signals (onSubscribe -> onNext* -> (onError | onComplete)). -
isCancelled
protected final boolean isCancelled()Returnstrueif this subscription is cancelled.falseresult is immediately outdated. Can be used by implementation to halt producing items in case the subscription was asynchronously cancelled. -
hasPendingErrors
protected final boolean hasPendingErrors()Returnstrueif the subscriber is to be completed exceptionally.falseresult 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'sonErrorwith the given exception after cancelling this subscription.flowInterruptedtells whether the error interrupted the normal flow of signals. -
cancelOnComplete
Calls downstream'sonCompleteafter cancelling this subscription. -
submitOnNext
Submits given item to the downstream, returningfalseand cancelling on failure.falseis also returned if the subscription is already cancelled or has pending errors. On such cases, caller should stop emitting items. -
currentDemand
protected long currentDemand()
-