Interface Multi<T>

Type Parameters:
T - item type
All Superinterfaces:
Flow.Publisher<T>, Subscribable<T>
All Known Implementing Classes:
ConcatPublisher, MultiFromOutputStream, MultiTappedPublisher, OutputStreamMulti

public interface Multi<T> extends Subscribable<T>
Represents a Flow.Publisher emitting zero or more items, optionally followed by an error or completion.
See Also:
  • Method Details

    • concat

      static <T> Multi<T> concat(Flow.Publisher<T> firstMulti, Flow.Publisher<T> secondMulti)
      Concat streams to one.
      Type Parameters:
      T - item type
      Parameters:
      firstMulti - first stream
      secondMulti - second stream
      Returns:
      Multi
    • concat

      @SafeVarargs static <T> Multi<T> concat(Flow.Publisher<T> firstPublisher, Flow.Publisher<T> secondPublisher, Flow.Publisher<T>... morePublishers)
      Concat streams to one.
      Type Parameters:
      T - item type
      Parameters:
      firstPublisher - first stream
      secondPublisher - second stream
      morePublishers - more publishers to concat
      Returns:
      Multi
    • concatArray

      @SafeVarargs static <T> Multi<T> concatArray(Flow.Publisher<T>... publishers)
      Concatenates an array of source Flow.Publishers by relaying items in order, non-overlappingly, one after the other finishes.
      Type Parameters:
      T - item type
      Parameters:
      publishers - more publishers to concat
      Returns:
      Multi
    • defer

      static <T> Multi<T> defer(Supplier<? extends Flow.Publisher<? extends T>> supplier)
      Call the given supplier function for each individual downstream Subscriber to return a Flow.Publisher to subscribe to.
      Type Parameters:
      T - the element type of the sequence
      Parameters:
      supplier - the callback to return a Flow.Publisher for each Subscriber
      Returns:
      Multi
      Throws:
      NullPointerException - if supplier is null
    • empty

      static <T> Multi<T> empty()
      Get a Multi instance that completes immediately.
      Type Parameters:
      T - item type
      Returns:
      Multi
    • error

      static <T> Multi<T> error(Throwable error)
      Create a Multi instance that reports the given exception to its subscriber(s). The exception is reported by invoking Flow.Subscriber.onError(java.lang.Throwable) when Flow.Publisher.subscribe(Subscriber) is called.
      Type Parameters:
      T - item type
      Parameters:
      error - exception to hold
      Returns:
      Multi
      Throws:
      NullPointerException - if error is null
    • from

      @Deprecated static <T> Multi<T> from(CompletionStage<T> completionStage)
      Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.

      A null result from the CompletionStage will yield a NullPointerException signal.

      Type Parameters:
      T - the element type of the stage and result
      Parameters:
      completionStage - the CompletionStage to
      Returns:
      Multi
      See Also:
    • from

      @Deprecated static <T> Multi<T> from(CompletionStage<T> completionStage, boolean nullMeansEmpty)
      Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.
      Type Parameters:
      T - the element type of the stage and result
      Parameters:
      completionStage - the CompletionStage to
      nullMeansEmpty - if true, a null result is interpreted to be an empty sequence if false, the resulting sequence fails with NullPointerException
      Returns:
      Multi
    • from

      @Deprecated static <T> Multi<T> from(Iterable<T> iterable)
      Deprecated.
      Create a Multi instance that publishes the given iterable.
      Type Parameters:
      T - item type
      Parameters:
      iterable - iterable to publish
      Returns:
      Multi
      Throws:
      NullPointerException - if iterable is null
    • from

      @Deprecated static <T> Multi<T> from(Flow.Publisher<T> source)
      Create a Multi instance wrapped around the given publisher.
      Type Parameters:
      T - item type
      Parameters:
      source - source publisher
      Returns:
      Multi
      Throws:
      NullPointerException - if source is null
    • from

      @Deprecated static <T> Multi<T> from(Single<T> single)
      Create a Multi instance wrapped around the given Single.
      Type Parameters:
      T - item type
      Parameters:
      single - source Single publisher
      Returns:
      Multi
      Throws:
      NullPointerException - if source is null
    • from

      @Deprecated static <T> Multi<T> from(Stream<T> stream)
      Deprecated.
      Create a Multi instance that publishes the given Stream.

      Note that Streams can be only consumed once, therefore, the returned Multi will signal IllegalStateException if multiple subscribers try to consume it.

      The operator calls BaseStream.close() when the stream finishes, fails or the flow gets canceled. To avoid closing the stream automatically, it is recommended to turn the Stream into an Iterable via BaseStream.iterator() and use create(Iterable):

      
           Stream<T> stream = ...
           Multi<T> multi = Multi.create(stream::iterator);
           
      Type Parameters:
      T - item type
      Parameters:
      stream - the Stream to publish
      Returns:
      Multi
      Throws:
      NullPointerException - if stream is null
    • create

      static <T> Multi<T> create(CompletionStage<T> completionStage)
      Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.

      A null result from the CompletionStage will yield a NullPointerException signal.

      Type Parameters:
      T - the element type of the stage and result
      Parameters:
      completionStage - the CompletionStage to
      Returns:
      Multi
      See Also:
    • create

      static <T> Multi<T> create(CompletionStage<T> completionStage, boolean nullMeansEmpty)
      Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.
      Type Parameters:
      T - the element type of the stage and result
      Parameters:
      completionStage - the CompletionStage to
      nullMeansEmpty - if true, a null result is interpreted to be an empty sequence if false, the resulting sequence fails with NullPointerException
      Returns:
      Multi
    • create

      static <T> Multi<T> create(Iterable<T> iterable)
      Create a Multi instance that publishes the given iterable.
      Type Parameters:
      T - item type
      Parameters:
      iterable - iterable to publish
      Returns:
      Multi
      Throws:
      NullPointerException - if iterable is null
    • create

      static <T> Multi<T> create(Flow.Publisher<T> source)
      Create a Multi instance wrapped around the given publisher.
      Type Parameters:
      T - item type
      Parameters:
      source - source publisher
      Returns:
      Multi
      Throws:
      NullPointerException - if source is null
    • create

      static <T> Multi<T> create(Single<T> single)
      Create a Multi instance wrapped around the given Single.
      Type Parameters:
      T - item type
      Parameters:
      single - source Single publisher
      Returns:
      Multi
      Throws:
      NullPointerException - if source is null
    • create

      static <T> Multi<T> create(Stream<T> stream)
      Create a Multi instance that publishes the given Stream.

      Note that Streams can be only consumed once, therefore, the returned Multi will signal IllegalStateException if multiple subscribers try to consume it.

      The operator calls BaseStream.close() when the stream finishes, fails or the flow gets canceled. To avoid closing the stream automatically, it is recommended to turn the Stream into an Iterable via BaseStream.iterator() and use create(Iterable):

      
           Stream<T> stream = ...
           Multi<T> multi = Multi.create(stream::iterator);
           
      Type Parameters:
      T - item type
      Parameters:
      stream - the Stream to publish
      Returns:
      Multi
      Throws:
      NullPointerException - if stream is null
    • interval

      static Multi<Long> interval(long period, TimeUnit unit, ScheduledExecutorService executor)
      Signal 0L, 1L and so on periodically to the downstream.

      Note that if the downstream applies backpressure, subsequent values may be delivered instantly upon further requests from the downstream.

      Parameters:
      period - the initial and in-between time
      unit - the time unit
      executor - the scheduled executor to use for the periodic emission
      Returns:
      Multi
      Throws:
      NullPointerException - if unit or executor is null
    • interval

      static Multi<Long> interval(long initialDelay, long period, TimeUnit unit, ScheduledExecutorService executor)
      Signal 0L after an initial delay, then 1L, 2L and so on periodically to the downstream.

      Note that if the downstream applies backpressure, subsequent values may be delivered instantly upon further requests from the downstream.

      Parameters:
      initialDelay - the time before signaling 0L
      period - the in-between wait time for values 1L, 2L and so on
      unit - the time unit
      executor - the scheduled executor to use for the periodic emission
      Returns:
      Multi
      Throws:
      NullPointerException - if unit or executor is null
    • just

      static <T> Multi<T> just(Collection<T> items)
      Create a Multi instance that publishes the given items to a single subscriber.
      Type Parameters:
      T - item type
      Parameters:
      items - items to publish
      Returns:
      Multi
      Throws:
      NullPointerException - if items is null
    • just

      @SafeVarargs static <T> Multi<T> just(T... items)
      Create a Multi instance that publishes the given items to a single subscriber.
      Type Parameters:
      T - item type
      Parameters:
      items - items to publish
      Returns:
      Multi
      Throws:
      NullPointerException - if items is null
    • never

      static <T> Multi<T> never()
      Get a Multi instance that never completes.
      Type Parameters:
      T - item type
      Returns:
      Multi
    • range

      static Multi<Integer> range(int start, int count)
      Emits a range of ever increasing integers.
      Parameters:
      start - the initial integer value
      count - the number of integers to emit
      Returns:
      Multi
      Throws:
      IllegalArgumentException - if count is negative
    • rangeLong

      static Multi<Long> rangeLong(long start, long count)
      Emits a range of ever increasing longs.
      Parameters:
      start - the initial long value
      count - the number of longs to emit
      Returns:
      Multi
      Throws:
      IllegalArgumentException - if count is negative
    • singleton

      static <T> Multi<T> singleton(T item)
      Create a Multi that emits a pre-existing item and then completes.
      Type Parameters:
      T - the type of the item
      Parameters:
      item - the item to emit.
      Returns:
      Multi
      Throws:
      NullPointerException - if item is null
    • timer

      static Multi<Long> timer(long time, TimeUnit unit, ScheduledExecutorService executor)
      Signal 0L and complete the sequence after the given time elapsed.
      Parameters:
      time - the time to wait before signaling 0L and completion
      unit - the unit of time
      executor - the executor to run the waiting on
      Returns:
      Multi
      Throws:
      NullPointerException - if unit or executor is null
    • collect

      default <U> Single<U> collect(Collector<T,U> collector)
      Collect the items of this Multi instance into a Single.
      Type Parameters:
      U - collector container type
      Parameters:
      collector - collector to use
      Returns:
      Single
      Throws:
      NullPointerException - if collector is null
    • collect

      default <U> Single<U> collect(Supplier<? extends U> collectionSupplier, BiConsumer<U,T> accumulator)
      Collect the items of this Multi into a collection provided via a Supplier and mutated by a BiConsumer callback.
      Type Parameters:
      U - the type of the collection and result
      Parameters:
      collectionSupplier - the Supplier that is called for each incoming Flow.Subscriber to create a fresh collection to collect items into
      accumulator - the BiConsumer that receives the collection and the current item to put in
      Returns:
      Single
      Throws:
      NullPointerException - if collectionSupplier or combiner is null
    • collectList

      default Single<List<T>> collectList()
      Collect the items of this Multi instance into a Single of List.
      Returns:
      Single
    • collectStream

      default <A, R> Single<R> collectStream(Collector<T,A,R> collector)
      Collects up upstream items with the help of a the callbacks of a Collector.
      Type Parameters:
      A - the accumulator type
      R - the result type
      Parameters:
      collector - the collector whose supplier(), accumulator() and finisher() callbacks are used for collecting upstream items into a final form.
      Returns:
      Single
      Throws:
      NullPointerException - if collector is null
    • compose

      default <U> Multi<U> compose(Function<? super Multi<T>,? extends Flow.Publisher<? extends U>> composer)
      Apply the given composer function to the current Multi instance and return aMulti wrapping the returned Flow.Publisher of this function.

      Note that the composer function is executed upon calling this method immediately and not when the resulting sequence gets subscribed to.

      Type Parameters:
      U - the output element type
      Parameters:
      composer - the function that receives the current Multi instance and should return a Flow.Publisher to be wrapped into a Multie to be returned by the method
      Returns:
      Multi
      Throws:
      NullPointerException - if composer is null
    • defaultIfEmpty

      default Multi<T> defaultIfEmpty(T defaultItem)
      Signals the default item if the upstream is empty.
      Specified by:
      defaultIfEmpty in interface Subscribable<T>
      Parameters:
      defaultItem - the item to signal if the upstream is empty
      Returns:
      Multi
      Throws:
      NullPointerException - if defaultItem is null
    • defaultIfEmpty

      default Multi<T> defaultIfEmpty(Supplier<? extends T> supplier)
      Signals the default item supplied by specified supplier if the upstream is empty.
      Specified by:
      defaultIfEmpty in interface Subscribable<T>
      Parameters:
      supplier - of the default value
      Returns:
      Multi
      Throws:
      NullPointerException - if supplier is null
    • distinct

      default Multi<T> distinct()
      Filter out all duplicates.
      Returns:
      Multi
    • dropWhile

      default Multi<T> dropWhile(Predicate<? super T> predicate)
      Drop the longest prefix of elements from this stream that satisfy the given predicate. As long as predicate returns true, items from upstream are NOT sent to downstream but being dropped, predicate is never called again after it returns false for the first time.
      Parameters:
      predicate - predicate to filter stream with
      Returns:
      Multi
    • filter

      default Multi<T> filter(Predicate<? super T> predicate)
      Filter stream items with provided predicate.
      Parameters:
      predicate - predicate to filter stream with
      Returns:
      Multi
    • first

      default Single<T> first()
      Get the first item of this Multi instance as a Single.
      Returns:
      Single
    • flatMap

      default <U> Multi<U> flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> publisherMapper)
      Transform item with supplied function and flatten resulting Flow.Publisher to downstream.
      Specified by:
      flatMap in interface Subscribable<T>
      Type Parameters:
      U - output item type
      Parameters:
      publisherMapper - Function receiving item as parameter and returning Flow.Publisher
      Returns:
      Multi
    • flatMap

      default <U> Multi<U> flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> mapper, long maxConcurrency, boolean delayErrors, long prefetch)
      Transform item with supplied function and flatten resulting Flow.Publisher to downstream while limiting the maximum number of concurrent inner Flow.Publishers and their in-flight item count, optionally aggregating and delaying all errors until all sources terminate.
      Type Parameters:
      U - output item type
      Parameters:
      mapper - Function receiving item as parameter and returning Flow.Publisher
      maxConcurrency - the maximum number of inner sources to run
      delayErrors - if true, any error from the main and inner sources are aggregated and delayed until all of them terminate
      prefetch - the number of items to request upfront from the inner sources, then request 75% more after 75% has been delivered
      Returns:
      Multi
    • flatMapCompletionStage

      default <U> Multi<U> flatMapCompletionStage(Function<? super T,? extends CompletionStage<? extends U>> mapper)
      Transform item with supplied function and flatten resulting CompletionStage results to downstream. As reactive streams forbids null values, error signal with NullPointerException is sent to downstream when CompletionStage result is null.
      Type Parameters:
      U - output item type
      Parameters:
      mapper - Function receiving item as parameter and returning CompletionStage
      Returns:
      Multi
      Throws:
      NullPointerException - if mapper is null
    • flatMapIterable

      default <U> Multi<U> flatMapIterable(Function<? super T,? extends Iterable<? extends U>> iterableMapper)
      Transform item with supplied function and flatten resulting Iterable to downstream.
      Specified by:
      flatMapIterable in interface Subscribable<T>
      Type Parameters:
      U - output item type
      Parameters:
      iterableMapper - Function receiving item as parameter and returning Iterable
      Returns:
      Multi
    • flatMapIterable

      default <U> Multi<U> flatMapIterable(Function<? super T,? extends Iterable<? extends U>> iterableMapper, int prefetch)
      Transform item with supplied function and flatten resulting Iterable to downstream.
      Type Parameters:
      U - output item type
      Parameters:
      iterableMapper - Function receiving item as parameter and returning Iterable
      prefetch - the number of upstream items to request upfront, then 75% of this value after 75% received and mapped
      Returns:
      Multi
    • flatMapOptional

      default <U> Multi<U> flatMapOptional(Function<? super T,Optional<? extends U>> mapper)
      Transform item with supplied function and flatten resulting Optional to downstream as one item if present or nothing if empty.
      Type Parameters:
      U - output item type
      Parameters:
      mapper - Function receiving item as parameter and returning Optional
      Returns:
      Multi
    • limit

      default Multi<T> limit(long limit)
      Limit stream to allow only specified number of items to pass.
      Parameters:
      limit - with expected number of items to be produced
      Returns:
      Multi
    • map

      default <U> Multi<U> map(Function<? super T,? extends U> mapper)
      Map this Multi instance to a new Multi of another type using the given Function.
      Specified by:
      map in interface Subscribable<T>
      Type Parameters:
      U - mapped item type
      Parameters:
      mapper - mapper
      Returns:
      Multi
      Throws:
      NullPointerException - if mapper is null
    • observeOn

      default Multi<T> observeOn(Executor executor)
      Re-emit the upstream's signals to the downstream on the given executor's thread using a default buffer size of 32 and errors skipping ahead of items.
      Specified by:
      observeOn in interface Subscribable<T>
      Parameters:
      executor - the executor to signal the downstream from.
      Returns:
      Multi
      Throws:
      NullPointerException - if executor is null
      See Also:
    • observeOn

      default Multi<T> observeOn(Executor executor, int bufferSize, boolean delayError)
      Re-emit the upstream's signals to the downstream on the given executor's thread.
      Parameters:
      executor - the executor to signal the downstream from.
      bufferSize - the number of items to prefetch and buffer at a time
      delayError - if true, errors are emitted after items, if false, errors may cut ahead of items during emission
      Returns:
      Multi
      Throws:
      NullPointerException - if executor is null
    • onCancel

      default Multi<T> onCancel(Runnable onCancel)
      Executes given Runnable when a cancel signal is received.
      Specified by:
      onCancel in interface Subscribable<T>
      Parameters:
      onCancel - Runnable to be executed.
      Returns:
      Multi
    • onComplete

      default Multi<T> onComplete(Runnable onComplete)
      Executes given Runnable when onComplete signal is received.
      Specified by:
      onComplete in interface Subscribable<T>
      Parameters:
      onComplete - Runnable to be executed.
      Returns:
      Multi
    • onError

      default Multi<T> onError(Consumer<? super Throwable> onErrorConsumer)
      Executes given Runnable when onError signal is received.
      Specified by:
      onError in interface Subscribable<T>
      Parameters:
      onErrorConsumer - Consumer to be executed.
      Returns:
      Multi
    • onErrorResume

      default Multi<T> onErrorResume(Function<? super Throwable,? extends T> onError)
      Function providing one item to be submitted as onNext in case of onError signal is received.
      Specified by:
      onErrorResume in interface Subscribable<T>
      Parameters:
      onError - Function receiving Throwable as argument and producing one item to resume stream with.
      Returns:
      Multi
    • onErrorResumeWith

      default Multi<T> onErrorResumeWith(Function<? super Throwable,? extends Flow.Publisher<? extends T>> onError)
      Resume stream from supplied publisher if onError signal is intercepted.
      Specified by:
      onErrorResumeWith in interface Subscribable<T>
      Parameters:
      onError - supplier of new stream publisher
      Returns:
      Multi
    • onCompleteResume

      default Multi<T> onCompleteResume(T item)
      Resume stream from single item if onComplete signal is intercepted. Effectively do an append to the stream.
      Specified by:
      onCompleteResume in interface Subscribable<T>
      Parameters:
      item - one item to resume stream with
      Returns:
      Multi
    • onCompleteResumeWith

      default Multi<T> onCompleteResumeWith(Flow.Publisher<? extends T> publisher)
      Resume stream from supplied publisher if onComplete signal is intercepted.
      Specified by:
      onCompleteResumeWith in interface Subscribable<T>
      Parameters:
      publisher - new stream publisher
      Returns:
      Multi
    • onTerminate

      default Multi<T> onTerminate(Runnable onTerminate)
      Executes given Runnable when any of signals onComplete, onCancel or onError is received.
      Specified by:
      onTerminate in interface Subscribable<T>
      Parameters:
      onTerminate - Runnable to be executed.
      Returns:
      Multi
    • ifEmpty

      default Multi<T> ifEmpty(Runnable ifEmpty)
      Executes given Runnable when stream is finished without value(empty stream).
      Parameters:
      ifEmpty - Runnable to be executed.
      Returns:
      Multi
    • peek

      default Multi<T> peek(Consumer<? super T> consumer)
      Invoke provided consumer for every item in stream.
      Specified by:
      peek in interface Subscribable<T>
      Parameters:
      consumer - consumer to be invoked
      Returns:
      Multi
    • log

      default Multi<T> log()
      Log all signals onSubscribe, onNext, onError, onComplete, cancel and request coming to and from preceding operator.
      Returns:
      Multi
    • log

      default Multi<T> log(Level level)
      Log all signals onSubscribe, onNext, onError, onComplete, cancel and request coming to and from preceding operator.
      Parameters:
      level - a logging level value
      Returns:
      Multi
    • log

      default Multi<T> log(Level level, String loggerName)
      Log all signals onSubscribe, onNext, onError, onComplete, cancel and request coming to and from preceding operator.
      Parameters:
      level - a logging level value
      loggerName - custom logger name
      Returns:
      Multi
    • log

      default Multi<T> log(Level level, boolean trace)
      Log all signals onSubscribe, onNext, onError, onComplete, cancel and request coming to and from preceding operator.

      Enabled trace option has a negative impact on performance and should NOT be used in production.

      Parameters:
      level - a logging level value
      trace - if true position of operator is looked up from stack and logged
      Returns:
      Multi
    • reduce

      default Single<T> reduce(BiFunction<T,T,T> reducer)
      Combine subsequent items via a callback function and emit the final value result as a Single.

      If the upstream is empty, the resulting Single is also empty. If the upstream contains only one item, the reducer function is not invoked and the resulting Single will have only that single item.

      Parameters:
      reducer - the function called with the first value or the previous result, the current upstream value and should return a new value
      Returns:
      Single
    • reduce

      default <R> Single<R> reduce(Supplier<? extends R> supplier, BiFunction<R,T,R> reducer)
      Combine every upstream item with an accumulator value to produce a new accumulator value and emit the final accumulator value as a Single.
      Type Parameters:
      R - the accumulator and result type
      Parameters:
      supplier - the function to return the initial accumulator value for each incoming Subscriber
      reducer - the function that receives the current accumulator value, the current upstream value and should return a new accumulator value
      Returns:
      Single
    • retry

      default Multi<T> retry(long count)
      Retry a failing upstream at most the given number of times before giving up.
      Specified by:
      retry in interface Subscribable<T>
      Parameters:
      count - the number of times to retry; 0 means no retry at all
      Returns:
      Multi
      Throws:
      IllegalArgumentException - if count is negative
      See Also:
    • retry

      default Multi<T> retry(BiPredicate<? super Throwable,? super Long> predicate)
      Retry a failing upstream if the predicate returns true.
      Specified by:
      retry in interface Subscribable<T>
      Parameters:
      predicate - the predicate that receives the latest failure Throwable the number of times the retry happened so far (0-based) and should return true to retry the upstream again or false to signal the latest failure
      Returns:
      Multi
      Throws:
      NullPointerException - if predicate is null
      See Also:
    • retryWhen

      default <U> Multi<T> retryWhen(BiFunction<? super Throwable,? super Long,? extends Flow.Publisher<U>> whenFunction)
      Retry a failing upstream when the given function returns a publisher that signals an item.

      If the publisher returned by the function completes, the repetition stops and this Multi is completed. If the publisher signals an error, the repetition stops and this Multi will signal this error.

      Specified by:
      retryWhen in interface Subscribable<T>
      Type Parameters:
      U - the element type of the retry-signal sequence
      Parameters:
      whenFunction - the function that receives the latest failure Throwable the number of times the retry happened so far (0-based) and should return a Flow.Publisher that should signal an item to retry again, complete to stop and complete this Multi or signal an error to have this Multi emit that error as well.
      Returns:
      Multi
      Throws:
      NullPointerException - if whenFunction is null
    • skip

      default Multi<T> skip(long skip)
      Skip first n items, all the others are emitted.
      Parameters:
      skip - number of items to be skipped
      Returns:
      Multi
    • switchIfEmpty

      default Multi<T> switchIfEmpty(Flow.Publisher<T> other)
      Switch to the other publisher if the upstream is empty.
      Parameters:
      other - the publisher to switch to if the upstream is empty.
      Returns:
      Multi
      Throws:
      NullPointerException - if other is null
    • takeUntil

      default <U> Multi<T> takeUntil(Flow.Publisher<U> other)
      Relay upstream items until the other source signals an item or completes.
      Specified by:
      takeUntil in interface Subscribable<T>
      Type Parameters:
      U - the element type of the other sequence
      Parameters:
      other - the other sequence to signal the end of the main sequence
      Returns:
      Multi
      Throws:
      NullPointerException - if other is null
    • takeWhile

      default Multi<T> takeWhile(Predicate<? super T> predicate)
      Take the longest prefix of elements from this stream that satisfy the given predicate. As long as predicate returns true, items from upstream are sent to downstream, when predicate returns false stream is completed.
      Parameters:
      predicate - predicate to filter stream with
      Returns:
      Multi
    • timeout

      default Multi<T> timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor)
      Signals a TimeoutException if the upstream doesn't signal the next item, error or completion within the specified time.
      Specified by:
      timeout in interface Subscribable<T>
      Parameters:
      timeout - the time to wait for the upstream to signal
      unit - the time unit
      executor - the executor to use for waiting for the upstream signal
      Returns:
      Multi
      Throws:
      NullPointerException - if unit or executor is null
    • timeout

      default Multi<T> timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor, Flow.Publisher<T> fallback)
      Switches to a fallback single if the upstream doesn't signal the next item, error or completion within the specified time.
      Parameters:
      timeout - the time to wait for the upstream to signal
      unit - the time unit
      executor - the executor to use for waiting for the upstream signal
      fallback - the Single to switch to if the upstream doesn't signal in time
      Returns:
      Multi
      Throws:
      NullPointerException - if unit, executor or fallback is null
    • to

      default <U> U to(Function<? super Multi<T>,? extends U> converter)
      Apply the given converter function to the current Multi instance and return the value returned by this function.

      Note that the converter function is executed upon calling this method immediately and not when the resulting sequence gets subscribed to.

      Type Parameters:
      U - the output type
      Parameters:
      converter - the function that receives the current Multi instance and should return a value to be returned by the method
      Returns:
      the value returned by the function
      Throws:
      NullPointerException - if converter is null
    • forEach

      default Single<Void> forEach(Consumer<? super T> consumer)
      Terminal stage, invokes provided consumer for every item in the stream with no backpressure.
      Parameters:
      consumer - consumer to be invoked for each item
      Returns:
      Single completed when the stream terminates
    • forEachCompletionStage

      default Single<Void> forEachCompletionStage(Function<? super T,CompletionStage<Void>> function)
      Terminal stage, invokes provided consumer for every item in the stream with strict backpressure. Items are requested 1 by 1 with no prefetch always waiting for each completion stage to complete before requesting another item.
      Parameters:
      function - invoked for each item returning completion stage to signal asynchronous completion
      Returns:
      Single completed when the stream terminates
    • ignoreElements

      default Single<Void> ignoreElements()
      Terminal stage, ignore all items and complete returned Single<Void> successfully or exceptionally.
      Returns:
      Single completed when the stream terminates