Module methanol

Class AbstractSubscription<T>

java.lang.Object
com.github.mizosoft.methanol.internal.flow.AbstractSubscription<T>
All Implemented Interfaces:
Flow.Subscription
Direct Known Subclasses:
AbstractPollableSubscription

public abstract class AbstractSubscription<T> extends Object implements Flow.Subscription
An abstract Flow.Subscription that implements most of the machinery for execution and backpressure control.
  • Constructor Details

  • Method Details

    • request

      public final void request(long n)
      Specified by:
      request in interface Flow.Subscription
    • cancel

      public final void cancel()
      Specified by:
      cancel in interface Flow.Subscription
    • fireOrKeepAlive

      public void fireOrKeepAlive()
    • fireOrKeepAliveOnNext

      public void fireOrKeepAliveOnNext()
    • fireOrKeepAliveOnError

      public void fireOrKeepAliveOnError(Throwable exception)
    • emit

      protected abstract long emit(Flow.Subscriber<? super T> downstream, long emit)
      Emits at most emit items to downstream using submitOnNext(Subscriber, Object) as long as it returns true. 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 if emit itself is zero. If the underlying source is finished, the subscriber is completed with cancelOnComplete(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. calling cancel() or throwing from onNext or onSubscribe), or due to ending the normal flow of signals (onSubscribe -> onNext* -> (onError | onComplete)).
    • isCancelled

      protected final boolean isCancelled()
      Returns true 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()
      Returns true 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's onError with the given exception after cancelling this subscription. flowInterrupted tells whether the error interrupted the normal flow of signals.
    • cancelOnComplete

      protected final void cancelOnComplete(Flow.Subscriber<? super T> downstream)
      Calls downstream's onComplete after cancelling this subscription.
    • submitOnNext

      protected final boolean submitOnNext(Flow.Subscriber<? super T> downstream, T item)
      Submits given item to the downstream, returning false 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()