Class Publisher<T>
- Type Parameters:
T
- Type of items emitted.
- Direct Known Subclasses:
GroupedPublisher
,SubscribablePublisher
How to subscribe?
This class does not provide a way to subscribe using aPublisherSource.Subscriber
as such calls are
ambiguous about the intent whether the subscribe is part of the same source (a.k.a an operator) or it is a terminal
subscribe. If it is required to subscribe to a source, then a source adapter
can be used to
convert to a PublisherSource
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionafterCancel
(Runnable onCancel) Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.afterFinally
(TerminalSignalConsumer doFinally) Invokes the corresponding method onafterFinally
TerminalSignalConsumer
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.afterFinally
(Runnable doFinally) Invokes theafterFinally
Runnable
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.afterOnComplete
(Runnable onComplete) Invokes theonComplete
Runnable
argument afterPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.afterOnError
(Consumer<Throwable> onError) Invokes theonError
Consumer
argument afterPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.afterOnNext
(Consumer<? super T> onNext) Invokes theonNext
Consumer
argument afterPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.afterOnSubscribe
(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribe
Consumer
argument afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.afterRequest
(LongConsumer onRequest) Invokes theonRequest
LongConsumer
argument afterPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.afterSubscriber
(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscriber
methods after thePublisherSource.Subscriber
s of the returnedPublisher
.afterSubscription
(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods after thePublisherSource.Subscription
s of the returnedPublisher
.beforeCancel
(Runnable onCancel) Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.beforeFinally
(TerminalSignalConsumer doFinally) Invokes the corresponding method onbeforeFinally
TerminalSignalConsumer
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.beforeFinally
(Runnable doFinally) Invokes thebeforeFinally
Runnable
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.beforeOnComplete
(Runnable onComplete) Invokes theonComplete
Runnable
argument beforePublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.beforeOnError
(Consumer<Throwable> onError) Invokes theonError
Consumer
argument beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.beforeOnNext
(Consumer<? super T> onNext) Invokes theonNext
Consumer
argument beforePublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.beforeOnSubscribe
(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribe
Consumer
argument beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.beforeRequest
(LongConsumer onRequest) Invokes theonRequest
LongConsumer
argument beforePublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.beforeSubscriber
(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscriber
methods before thePublisherSource.Subscriber
s of the returnedPublisher
.beforeSubscription
(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscription
methods before thePublisherSource.Subscription
s of the returnedPublisher
.final <BC extends BufferStrategy.Accumulator<T,
B>, B>
Publisher<B>buffer
(BufferStrategy<T, BC, B> strategy) final <R> Publisher<R>
final <R> Single<R>
collect
(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> collector) Collects all items emitted by thisPublisher
into a single item.final Completable
Converts thisPublisher
to aCompletable
.concat
(Completable next) This method is likeconcat(Completable)
exceptnext
will be subscribed to and cancelled if thisPublisher
is cancelled or terminates withPublisherSource.Subscriber.onError(Throwable)
.static <T> Publisher<T>
Defers creation of aPublisher
till it is subscribed.distinct()
Only emits distinct signals observed by thisPublisher
.static <T> Publisher<T>
empty()
Creates a newPublisher
that completes when subscribed without emitting any item to itsPublisherSource.Subscriber
.static <T> Publisher<T>
Creates a newPublisher
that terminates itsPublisherSource.Subscriber
with an error without emitting any item to it.Filters items emitted by thisPublisher
.firstOrElse
(Supplier<T> defaultValueSupplier) final Completable
flatMapCompletable
(Function<? super T, ? extends Completable> mapper) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.final Completable
flatMapCompletable
(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.final Completable
flatMapCompletableDelayError
(Function<? super T, ? extends Completable> mapper) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.final Completable
flatMapCompletableDelayError
(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.final Completable
flatMapCompletableDelayError
(Function<? super T, ? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.final <R> Publisher<R>
flatMapConcatIterable
(Function<? super T, ? extends Iterable<? extends R>> mapper) final <R> Publisher<R>
flatMapConcatSingle
(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)
but the result is asynchronous.final <R> Publisher<R>
flatMapConcatSingle
(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous.final <R> Publisher<R>
flatMapConcatSingleDelayError
(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)
but the result is asynchronous.final <R> Publisher<R>
flatMapConcatSingleDelayError
(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous.final <R> Publisher<R>
flatMapMerge
(Function<? super T, ? extends Publisher<? extends R>> mapper) final <R> Publisher<R>
flatMapMerge
(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) final <R> Publisher<R>
flatMapMergeDelayError
(Function<? super T, ? extends Publisher<? extends R>> mapper) final <R> Publisher<R>
flatMapMergeDelayError
(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) final <R> Publisher<R>
flatMapMergeDelayError
(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) final <R> Publisher<R>
flatMapMergeSingle
(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)
but the result is asynchronous and results are unordered.final <R> Publisher<R>
flatMapMergeSingle
(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous and results are unordered.final <R> Publisher<R>
flatMapMergeSingleDelayError
(Function<? super T, ? extends Single<? extends R>> mapper) final <R> Publisher<R>
flatMapMergeSingleDelayError
(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous and results are unordered.final <R> Publisher<R>
flatMapMergeSingleDelayError
(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) This method is similar tomap(Function)
but the result is asynchronous and results are unordered.final Cancellable
static <T> Publisher<T>
from
(T value) Creates a newPublisher
that emitsvalue
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
from
(T... values) Creates a newPublisher
that emits allvalues
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
from
(T v1, T v2) Creates a newPublisher
that emitsv1
andv2
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
from
(T v1, T v2, T v3) Creates a newPublisher
that emitsv1
,v2
, andv3
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
fromBlockingIterable
(BlockingIterable<? extends T> iterable, LongSupplier timeoutSupplier, TimeUnit unit) Create a newPublisher
that when subscribed will get aBlockingIterator
viaBlockingIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static Publisher<byte[]>
fromInputStream
(InputStream stream) Deprecated.static Publisher<byte[]>
fromInputStream
(InputStream stream, int readChunkSize) Deprecated.static <T> Publisher<T>
fromInputStream
(InputStream stream, ByteArrayMapper<T> mapper) Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
as a mapped typeT
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
fromIterable
(Iterable<? extends T> iterable) Create a newPublisher
that when subscribed will get anIterator
viaIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.final <Key> Publisher<GroupedPublisher<Key,
T>> Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s.final <Key> Publisher<GroupedPublisher<Key,
T>> Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s.final <Key> Publisher<GroupedPublisher<Key,
T>> Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s.final <Key> Publisher<GroupedPublisher<Key,
T>> groupToMany
(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit) The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.final <Key> Publisher<GroupedPublisher<Key,
T>> groupToMany
(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit, int expectedGroupCountHint) The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.protected abstract void
handleSubscribe
(PublisherSource.Subscriber<? super T> subscriber) Handles a subscriber to thisPublisher
.final Completable
Ignores all elements emitted by thisPublisher
and forwards the termination signal to the returnedCompletable
.final <R> Publisher<R>
liftAsync
(PublisherOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators.final <R> Publisher<R>
liftSync
(PublisherOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators.final <R> Single<R>
liftSyncToSingle
(PublisherToSingleOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators.final <R> Publisher<R>
Transforms elements emitted by thisPublisher
into a different type.Merge twoPublisher
s together.static <T> Publisher<T>
Merge allPublisher
s together.static <T> Publisher<T>
Merge allPublisher
s together.static <T> Publisher<T>
mergeAllDelayError
(int maxConcurrency, Publisher<? extends T>... publishers) Merge allPublisher
s together.static <T> Publisher<T>
mergeAllDelayError
(Publisher<? extends T>... publishers) Merge allPublisher
s together.mergeDelayError
(Publisher<? extends T> other) Merge twoPublisher
s together.multicast
(int minSubscribers) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s.multicast
(int minSubscribers, boolean cancelUpstream) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s.multicast
(int minSubscribers, int queueLimit) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s.multicast
(int minSubscribers, int queueLimit, boolean cancelUpstream) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s.multicast
(int minSubscribers, int queueLimit, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s.multicast
(int minSubscribers, int queueLimit, Function<Throwable, Completable> terminalResubscribe) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s.multicastToExactly
(int expectedSubscribers) Deprecated.Usemulticast(int)
.multicastToExactly
(int expectedSubscribers, int queueLimit) Deprecated.Usemulticast(int, int)
.static <T> Publisher<T>
never()
Creates a newPublisher
that never emits any item to itsPublisherSource.Subscriber
and never call any terminal methods on it.final <R> Publisher<R>
Filters items so that only non-null
items of typePublisher
are emitted by the return value.onCompleteError
(Supplier<? extends Throwable> errorSupplier) Transform thisPublisher
sPublisherSource.Subscriber.onComplete()
signal intoPublisherSource.Subscriber.onError(Throwable)
signal (unlessnull
error returned fromerrorSupplier
).Transform errors emitted on thisPublisher
into aPublisherSource.Subscriber.onComplete()
signal (e.g.onErrorComplete
(Class<E> type) Transform errors emitted on thisPublisher
which matchtype
into aPublisherSource.Subscriber.onComplete()
signal (e.g.onErrorComplete
(Predicate<? super Throwable> predicate) Transform errors emitted on thisPublisher
which matchpredicate
into aPublisherSource.Subscriber.onComplete()
signal (e.g.onErrorMap
(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisPublisher
which matchtype
into a different error.onErrorMap
(Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisPublisher
into a different error.onErrorMap
(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisPublisher
which matchpredicate
into a different error.onErrorResume
(Class<E> type, Function<? super E, ? extends Publisher<? extends T>> nextFactory) onErrorResume
(Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) onErrorResume
(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) onErrorReturn
(Class<E> type, Function<? super E, ? extends T> itemSupplier) Transform errors emitted on thisPublisher
which matchtype
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g.onErrorReturn
(Function<? super Throwable, ? extends T> itemSupplier) Transform errors emitted on thisPublisher
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g.onErrorReturn
(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends T> itemSupplier) Transform errors emitted on thisPublisher
which matchpredicate
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g.Creates a newPublisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods.publishOn
(Executor executor, BooleanSupplier shouldOffload) Creates a newPublisher
that may use the passedExecutor
to invoke allPublisherSource.Subscriber
methods.range
(int begin, int end) range
(int begin, int end, int stride) repeat
(IntPredicate shouldRepeat) repeatWhen
(IntFunction<? extends Completable> repeatWhen) Re-subscribes to thisPublisher
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully.replay
(int history) Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but also retainshistory
of the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)
which are emitted to new downstreamPublisherSource.Subscriber
s before emitting new signals.Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but also retainshistoryHint
of the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)
which are emitted to new downstreamPublisherSource.Subscriber
s before emitting new signals.replay
(ReplayStrategy<T> replayStrategy) Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but will also retain some history ofPublisherSource.Subscriber.onNext(Object)
signals according to theReplayStrategy
replayStrategy
.replay
(Supplier<ReplayAccumulator<T>> accumulatorSupplier) Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but will also retain some history ofPublisherSource.Subscriber.onNext(Object)
signals according to theReplayAccumulator
accumulatorSupplier
.retry
(boolean terminateOnNextException, BiIntPredicate<Throwable> shouldRetry) retry
(BiIntPredicate<Throwable> shouldRetry) retryWhen
(boolean terminateOnNextException, BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisPublisher
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully.retryWhen
(BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisPublisher
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully.final <R> Publisher<R>
scanWith
(Supplier<? extends ScanWithMapper<? super T, ? extends R>> mapperSupplier) Deprecated.final <R> Publisher<R>
scanWith
(Supplier<R> initial, BiFunction<R, ? super T, R> accumulator) Apply aBiFunction
to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
and an accumulated state.final <R> Publisher<R>
scanWithLifetime
(Supplier<? extends ScanWithLifetimeMapper<? super T, ? extends R>> mapperSupplier) Deprecated.final <R> Publisher<R>
scanWithLifetimeMapper
(Supplier<? extends ScanLifetimeMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream.final <R> Publisher<R>
scanWithMapper
(Supplier<? extends ScanMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream.setContextOnSubscribe
(ContextMap context) Signifies that when the returnedPublisher
is subscribed to, theAsyncContext
will be shared instead of making acopy
.Skip items emitted by thisPublisher
until the first time the predicate is not satisfied.protected void
subscribeInternal
(PublisherSource.Subscriber<? super T> subscriber) A internal subscribe method similar toPublisherSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.subscribeOn
(Executor executor) Creates a newPublisher
that will use the passedExecutor
to invoke the following methods: AllPublisherSource.Subscription
methods. ThehandleSubscribe(PublisherSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
.subscribeOn
(Executor executor, BooleanSupplier shouldOffload) Creates a newPublisher
that may use the passedExecutor
to invoke the following methods: AllPublisherSource.Subscription
methods. ThehandleSubscribe(PublisherSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
.final <R> Publisher<R>
final <R> Publisher<R>
switchMapDelayError
(Function<? super T, ? extends Publisher<? extends R>> mapper) final <R> Publisher<R>
switchMapDelayError
(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxDelayedErrorsHint) takeAtMost
(long numElements) takeUntil
(Completable until) Takes elements untilCompletable
is terminated successfully or with failure.Takes elements whilePredicate
istrue
and then cancelPublisherSource.Subscription
of thisPublisher
once it returnsfalse
.Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.timeoutDemand
(long duration, TimeUnit unit) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.timeoutDemand
(long duration, TimeUnit unit, Executor executor) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.timeoutDemand
(Duration duration) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.timeoutDemand
(Duration duration, Executor executor) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.timeoutTerminal
(long duration, TimeUnit unit) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.timeoutTerminal
(long duration, TimeUnit unit, Executor timeoutExecutor) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.timeoutTerminal
(Duration duration) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.timeoutTerminal
(Duration duration, Executor timeoutExecutor) Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination.final CompletionStage<Collection<T>>
Convert thisPublisher
into aCompletionStage
with aCollection
containing the elements of thisPublisher
upon successful termination.final <R> CompletionStage<R>
toCompletionStage
(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) Convert thisPublisher
into aCompletionStage
of typePublisher
which represents all elements of thisPublisher
upon successful termination.final Future<Collection<T>>
toFuture()
Convert thisPublisher
into aFuture
with aCollection
containing the elements of thisPublisher
upon successful termination.final <R> Future<R>
toFuture
(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) final InputStream
toInputStream
(Function<? super T, byte[]> serializer) Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.final InputStream
toInputStream
(Function<? super T, byte[]> serializer, int queueCapacity) Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.final BlockingIterable<T>
final BlockingIterable<T>
toIterable
(int queueCapacityHint) Validate the outstanding demand (PublisherSource.Subscription.request(long)
minusPublisherSource.Subscriber.onNext(Object)
) does not go negative.validateOutstandingDemand
(ObjLongConsumer<T> onNextConsumer, LongBinaryConsumer requestConsumer) Validate the outstanding demand (PublisherSource.Subscription.request(long)
minusPublisherSource.Subscriber.onNext(Object)
) does not go negative.whenCancel
(Runnable onCancel) Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedPublisher
.whenFinally
(TerminalSignalConsumer doFinally) Invokes the corresponding method onwhenFinally
TerminalSignalConsumer
argument when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.whenFinally
(Runnable doFinally) Invokes thewhenFinally
Runnable
argument exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.whenOnComplete
(Runnable onComplete) Invokes theonComplete
Runnable
argument whenPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.whenOnError
(Consumer<Throwable> onError) Invokes theonError
Consumer
argument whenPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.whenOnNext
(Consumer<? super T> onNext) Invokes theonNext
Consumer
argument whenPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.whenOnSubscribe
(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribe
Consumer
argument whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.whenRequest
(LongConsumer onRequest) Invokes theonRequest
LongConsumer
argument whenPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.whenSubscriber
(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes methods on thatPublisherSource.Subscriber
when the corresponding methods are called forPublisherSource.Subscriber
s of the returnedPublisher
.whenSubscription
(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods when the corresponding methods are called forPublisherSource.Subscription
s of the returnedPublisher
.
-
Constructor Details
-
Publisher
protected Publisher()New instance.
-
-
Method Details
-
map
Transforms elements emitted by thisPublisher
into a different type.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { results.add(mapper.apply(t)); } return results;
-
cast
Cast thisPublisher
from typePublisher
to typePublisher
.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { results.add(clazz.cast(t)); } return results;
- Type Parameters:
R
- The resulting type of the cast operation.- Parameters:
clazz
- The type to cast to.- Returns:
- The cast of this
Publisher
to typePublisher
. Terminates with aClassCastException
if signals cannot be cast to typePublisher
. - See Also:
-
filter
Filters items emitted by thisPublisher
.This method provides a data transformation in sequential programming similar to:
List<T> results = ...; for (T t : resultOfThisPublisher()) { if (predicate.test(t)) { results.add(t); } } return results;
- Parameters:
predicate
- for the filter.- Returns:
- A
Publisher
that only emits the items that pass thepredicate
. - See Also:
-
ofType
Filters items so that only non-null
items of typePublisher
are emitted by the return value.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { if (clazz.isInstance(t)) { results.add((R) t); } } return results;
- Type Parameters:
R
- The resulting type of the cast operation.- Parameters:
clazz
- The type to filter and cast to.- Returns:
- a
Publisher
that only emits - See Also:
-
distinct
Only emits distinct signals observed by thisPublisher
. Signals are compared usingObject.hashCode()
andObject.equals(Object)
.This method provides a data transformation in sequential programming similar to:
Set<T> results = ...; for (T t : resultOfThisPublisher()) { results.add(t); } return results;
-
scanWith
Apply aBiFunction
to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
and an accumulated state.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; R state = initial.get(); for (T t : resultOfThisPublisher()) { state = accumulator.apply(state, t); results.add(state); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
initial
- Invoked on eachPublisherSource.subscribe(Subscriber)
and provides the initial state for eachPublisherSource.Subscriber
.accumulator
- Used to accumulate the current state in combination with eachPublisherSource.Subscriber.onNext(Object)
from thisPublisher
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
-
scanWith
@Deprecated public final <R> Publisher<R> scanWith(Supplier<? extends ScanWithMapper<? super T, ? extends R>> mapperSupplier) Deprecated.Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithMapper<T, R> mapper = mapperSupplier.get(); try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { if (mapTerminal.test(state)) { results.add(mapper.mapOnError(cause)); return; } throw cause; } if (mapTerminal.test(state)) { results.add(mapper.mapOnComplete()); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
mapperSupplier
- Invoked on eachPublisherSource.subscribe(Subscriber)
and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
-
scanWithMapper
public final <R> Publisher<R> scanWithMapper(Supplier<? extends ScanMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithLifetimeMapperExt<T, R> mapper = mapperSupplier.get(); MappedTerminal<R> mapped = null; try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { mapped = mapper.mapOnError(cause); if (mapped == null) { throw cause; } } if (mapped == null) { mapped = mapper.mapOnComplete(); } if (mapped.onNextValid()) { results.add(mapped.onNext()); } if (mapped.terminal() != null) { throw mapped.terminal(); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
mapperSupplier
- Invoked on eachPublisherSource.subscribe(Subscriber)
and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
-
scanWithLifetime
@Deprecated public final <R> Publisher<R> scanWithLifetime(Supplier<? extends ScanWithLifetimeMapper<? super T, ? extends R>> mapperSupplier) Deprecated.Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream. Additionally theScanWithLifetimeMapper.afterFinally()
method will be invoked on terminal or cancel signals which enables cleanup of state (if required). This provides a similar lifetime management asTerminalSignalConsumer
.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithLifetimeMapper<T, R> mapper = mapperSupplier.get(); try { try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { if (mapTerminal.test(state)) { results.add(mapper.mapOnError(cause)); return; } throw cause; } if (mapTerminal.test(state)) { results.add(mapper.mapOnComplete()); } } finally { mapper.afterFinally(); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
mapperSupplier
- Invoked on eachPublisherSource.subscribe(Subscriber)
and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
-
scanWithLifetimeMapper
public final <R> Publisher<R> scanWithLifetimeMapper(Supplier<? extends ScanLifetimeMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream. Additionally theScanLifetimeMapper.afterFinally()
method will be invoked on terminal or cancel signals which enables cleanup of state (if required). This provides a similar lifetime management asTerminalSignalConsumer
.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithLifetimeMapperExt<T, R> mapper = mapperSupplier.get(); try { MappedTerminal<R> mapped = null; try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { mapped = mapper.mapOnError(cause); if (mapped == null) { throw cause; } } if (mapped == null) { mapped = mapper.mapOnComplete(); } if (mapped.onNextValid()) { results.add(mapped.onNext()); } if (mapped.terminal() != null) { throw mapped.terminal(); } } finally { mapper.afterFinally(); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
mapperSupplier
- Invoked on eachPublisherSource.subscribe(Subscriber)
and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
-
onErrorComplete
Transform errors emitted on thisPublisher
into aPublisherSource.Subscriber.onComplete()
signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { // ignored } return results;
- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
into aPublisherSource.Subscriber.onComplete()
signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisPublisher
which matchtype
into aPublisherSource.Subscriber.onComplete()
signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!type.isInstance(cause)) { throw cause; } } return results;
- Type Parameters:
E
- TheThrowable
type.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
which matchtype
into aPublisherSource.Subscriber.onComplete()
signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisPublisher
which matchpredicate
into aPublisherSource.Subscriber.onComplete()
signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!predicate.test(cause)) { throw cause; } } return results;
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed to andPublisherSource.Subscriber.onComplete()
signal. Returnsfalse
to propagate the error.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
which matchpredicate
into aPublisherSource.Subscriber.onComplete()
signal (e.g. swallows the error). - See Also:
-
onErrorReturn
Transform errors emitted on thisPublisher
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { results.add(itemSupplier.apply(cause)); } return results;
- Parameters:
itemSupplier
- returns the element to emit toPublisherSource.Subscriber.onNext(Object)
.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g. swallows the error). - See Also:
-
onErrorReturn
public final <E extends Throwable> Publisher<T> onErrorReturn(Class<E> type, Function<? super E, ? extends T> itemSupplier) Transform errors emitted on thisPublisher
which matchtype
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!type.isInstance(cause)) { throw cause; } results.add(itemSupplier.apply(cause)); } return results;
- Type Parameters:
E
- The type ofThrowable
to transform.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.itemSupplier
- returns the element to emit toPublisherSource.Subscriber.onNext(Object)
.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g. swallows the error). - See Also:
-
onCompleteError
Transform thisPublisher
sPublisherSource.Subscriber.onComplete()
signal intoPublisherSource.Subscriber.onError(Throwable)
signal (unlessnull
error returned fromerrorSupplier
).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); terminalOfThisPublisher(); Throwable cause = errorSupplier.get() if (cause != null) { throw cause; }
- Parameters:
errorSupplier
- returns the error to emit toPublisherSource.Subscriber.onError(Throwable)
. if the return value isnull
then complete withPublisherSource.Subscriber.onComplete()
.- Returns:
- A
Publisher
which transform thisPublisher
sPublisherSource.Subscriber.onComplete()
signal intoPublisherSource.Subscriber.onError(Throwable)
signal (unlessnull
error returned fromerrorSupplier
).
-
onErrorReturn
public final Publisher<T> onErrorReturn(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends T> itemSupplier) Transform errors emitted on thisPublisher
which matchpredicate
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!predicate.test(cause)) { throw cause; } results.add(itemSupplier.apply(cause)); } return result;
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed toPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals. Returnsfalse
to propagate the error.itemSupplier
- returns the element to emit toPublisherSource.Subscriber.onNext(Object)
.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
intoPublisherSource.Subscriber.onNext(Object)
thenPublisherSource.Subscriber.onComplete()
signals (e.g. swallows the error). - See Also:
-
onErrorMap
Transform errors emitted on thisPublisher
into a different error.This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { throw mapper.apply(cause); } return results;
-
onErrorMap
public final <E extends Throwable> Publisher<T> onErrorMap(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisPublisher
which matchtype
into a different error.This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (type.isInstance(cause)) { throw mapper.apply(cause); } else { throw cause; } } return results;
- Type Parameters:
E
- The type ofThrowable
to transform.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.mapper
- returns the error used to terminate the returnedPublisher
.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
into a different error. - See Also:
-
onErrorMap
public final Publisher<T> onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisPublisher
which matchpredicate
into a different error.This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (predicate.test(cause)) { throw mapper.apply(cause); } else { throw cause; } } return results;
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed viamapper
. Returnsfalse
to propagate the original error.mapper
- returns the error used to terminate the returnedPublisher
.- Returns:
- A
Publisher
which transform errors emitted on thisPublisher
into a different error. - See Also:
-
onErrorResume
public final Publisher<T> onErrorResume(Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) Recover from any error emitted by thisPublisher
by using anotherPublisher
provided by the passednextFactory
.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } return results;
-
onErrorResume
public final <E extends Throwable> Publisher<T> onErrorResume(Class<E> type, Function<? super E, ? extends Publisher<? extends T>> nextFactory) Recover from errors emitted by thisPublisher
which matchtype
by using anotherPublisher
provided by the passednextFactory
.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { if (type.isInstance(cause)) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } else { throw cause; } } return results;
- Type Parameters:
E
- The type ofThrowable
to transform.- Parameters:
type
- TheThrowable
type to filter, operator will not apply for errors which don't match this type.nextFactory
- Returns the nextPublisher
, when thisPublisher
emits an error.- Returns:
- A
Publisher
that recovers from an error from thisPublisher
by using anotherPublisher
provided by the passednextFactory
. - See Also:
-
onErrorResume
public final Publisher<T> onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) Recover from errors emitted by thisPublisher
which matchpredicate
by using anotherPublisher
provided by the passednextFactory
.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { if (predicate.test(cause)) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } else { throw cause; } } return results;
- Parameters:
predicate
- returnstrue
if theThrowable
should be transformed vianextFactory
. Returnsfalse
to propagate the original error.nextFactory
- Returns the nextPublisher
, when thisPublisher
emits an error.- Returns:
- A
Publisher
that recovers from an error from thisPublisher
by using anotherPublisher
provided by the passednextFactory
. - See Also:
-
flatMapMerge
public final <R> Publisher<R> flatMapMerge(Function<? super T, ? extends Publisher<? extends R>> mapper) Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.To control the amount of concurrent processing done by this operator see
flatMapMerge(Function, int)
.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results;
-
flatMapMerge
public final <R> Publisher<R> flatMapMerge(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results;
-
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This is the same as
flatMapMerge(Function)
just that if any mappedPublisher
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedPublisher
s to terminate and then terminate the returnedPublisher
with all errors emitted by the mappedPublisher
s.To control the amount of concurrent processing done by this operator see
flatMapMergeDelayError(Function, int)
.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);
-
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This is the same as
flatMapMerge(Function)
just that if any mappedPublisher
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedPublisher
s to terminate and then terminate the returnedPublisher
with all errors emitted by the mappedPublisher
s.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);
-
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This is the same as
flatMapMerge(Function)
just that if any mappedPublisher
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedPublisher
s to terminate and then terminate the returnedPublisher
with all errors emitted by the mappedPublisher
s.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);
- Type Parameters:
R
- The type of mappedPublisher
.- Parameters:
mapper
- Convert each item emitted by thisPublisher
into anotherPublisher
.maxConcurrency
- Maximum amount of outstanding upstreamdemand
.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A new
Publisher
which flattens the emissions from all mappedPublisher
s. - See Also:
-
flatMapMergeSingle
public final <R> Publisher<R> flatMapMergeSingle(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)
but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.To control the amount of concurrent processing done by this operator see
flatMapMergeSingle(Function, int)
.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { R r = future.get(); // Throws if the processing for this item failed. results.add(r); } return results;
-
flatMapMergeSingle
public final <R> Publisher<R> flatMapMergeSingle(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { R r = future.get(); // Throws if the processing for this item failed. results.add(r); } return results;
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper) Map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.The behavior is the same as
flatMapMergeSingle(Function, int)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and allSingle
s to terminate and then terminate the returnedPublisher
with errors emitted by theSingle
s produced by themapper
.To control the amount of concurrent processing done by this operator see
flatMapMergeSingleDelayError(Function, int)
.This method is similar to
map(Function)
but the result is asynchronous, unordered, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { processResult(mapper.apply(t)); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.The behavior is the same as
flatMapMergeSingle(Function, int)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and allSingle
s to terminate and then terminate the returnedPublisher
with all errors emitted by theSingle
s produced by themapper
.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { processResult(mapper.apply(t)); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) This method is similar tomap(Function)
but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.The behavior is the same as
flatMapMergeSingle(Function, int)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and allSingle
s to terminate and then terminate the returnedPublisher
with errors emitted by theSingle
s produced by themapper
.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { processResult(mapper.apply(t)); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
-
flatMapCompletable
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If the returned
Completable
should wait for the termination of all mappedCompletable
s when any one of them terminates with a failure,flatMapCompletableDelayError(Function)
should be used.To control the amount of concurrent processing done by this operator see
flatMapCompletable(Function, int)
.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<Void>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. }
- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aCompletable
.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletable
public final Completable flatMapCompletable(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If the returned
Completable
should wait for the termination of all mappedCompletable
s when any one of them terminates with a failure,flatMapCompletableDelayError(Function)
should be used.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<Void>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. }
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.maxConcurrency
- Maximum activeCompletable
s at any time.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If any mapped
Completable
terminates with an error the returnedCompletable
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedCompletable
s to terminate.To control the amount of concurrent processing done by this operator see
flatMapCompletableDelayError(Function, int)
.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { mapper.apply(t); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If any mapped
Completable
terminates with an error the returnedCompletable
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedCompletable
s to terminate.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { mapper.apply(t); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.maxConcurrency
- Maximum activeCompletable
s at any time.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint) Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If any mapped
Completable
terminates with an error the returnedCompletable
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedCompletable
s to terminate.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { mapper.apply(t); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.maxConcurrency
- Maximum activeCompletable
s at any time.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapConcatSingle
public final <R> Publisher<R> flatMapConcatSingle(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)
but the result is asynchronous. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>. Each mappedSingle
<Publisher
> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher
.To control the amount of concurrent processing done by this operator see
flatMapConcatSingle(Function, int)
.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } for (Future<R> future : futures) { processResult(future.get()); // Throws if the processing for this item failed. }
-
flatMapConcatSingle
public final <R> Publisher<R> flatMapConcatSingle(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>. Each mappedSingle
<Publisher
> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher
.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } for (Future<R> future : futures) { processResult(future.get()); // Throws if the processing for this item failed. }
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
-
flatMapConcatSingleDelayError
public final <R> Publisher<R> flatMapConcatSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)
but the result is asynchronous. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>. Each mappedSingle
<Publisher
> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher
.The behavior is the same as
flatMapConcatSingle(Function)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not terminate until thisPublisher
and allSingle
s to terminate.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { processResult(future.get()); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
-
flatMapConcatSingleDelayError
public final <R> Publisher<R> flatMapConcatSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)
but the result is asynchronous. More specifically, map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>. Each mappedSingle
<Publisher
> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher
.The behavior is the same as
flatMapConcatSingle(Function)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not terminate until thisPublisher
and allSingle
s to terminate.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { processResult(future.get()); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
-
flatMapConcatIterable
public final <R> Publisher<R> flatMapConcatIterable(Function<? super T, ? extends Iterable<? extends R>> mapper) Create aPublisher
that flattens each element returned by theIterable.iterator()
frommapper
.The mapper
Function
will only be called when the previously returnedIterator
has returnedfalse
fromIterator.hasNext()
.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<R> results = ...; for (T t : resultOfThisPublisher()) { Iterable<? extends R> itr = mapper.apply(t); itr.forEach(results::add); } return results;
- Type Parameters:
R
- The elements returned by theIterable
.- Parameters:
mapper
- AFunction
that returns anIterable
for each element.- Returns:
- a
Publisher
that flattens each element returned by theIterable.iterator()
frommapper
. The results will be sequential for eachIterator
, and overall for all calls toIterable.iterator()
-
switchMap
public final <R> Publisher<R> switchMap(Function<? super T, ? extends Publisher<? extends R>> mapper) Return aPublisher
that will switch to the latestPublisher
emitted frommapper
and the priorPublisher
will be cancelled. Both upstream and the last switchedPublisher
must complete before the returnedPublisher
completes. If either upstream or the currently activePublisher
terminate in error the returnedPublisher
is terminated with that error.ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { // Approximation: control flow is simplified here but when a later mapper is applied any incomplete // results from a previous mapper are cancelled and result in empty results. return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results;
-
switchMapDelayError
public final <R> Publisher<R> switchMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) Return aPublisher
that will switch to the latestPublisher
emitted frommapper
and the priorPublisher
will be cancelled. Both upstream and the last switchedPublisher
must terminate before the returnedPublisher
terminates (including errors). -
switchMapDelayError
public final <R> Publisher<R> switchMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxDelayedErrorsHint) Return aPublisher
that will switch to the latestPublisher
emitted frommapper
and the priorPublisher
will be cancelled. Both upstream and the last switchedPublisher
must terminate before the returnedPublisher
terminates (including errors).- Type Parameters:
R
- The type of mappedPublisher
.- Parameters:
mapper
- Convert each item emitted by thisPublisher
into anotherPublisher
.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A
Publisher
that will switch to the latestPublisher
emitted frommapper
and the priorPublisher
will be cancelled. - See Also:
-
merge
Merge twoPublisher
s together. There is no guaranteed ordering of events emitted from the returnedPublisher
.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfThisPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. } return mergedResults;
-
mergeDelayError
Merge twoPublisher
s together. There is no guaranteed ordering of events emitted from the returnedPublisher
. If eitherPublisher
fails the error propagation will be delayed until both terminate.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfThisPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); return mergedResults;
-
whenOnSubscribe
public final Publisher<T> whenOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribe
Consumer
argument whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onSubscribe
will be invoked relative toPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is undefined. If you need strict ordering seebeforeOnSubscribe(Consumer)
andafterOnSubscribe(Consumer)
.- Parameters:
onSubscribe
- Invoked whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenOnNext
Invokes theonNext
Consumer
argument whenPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onNext
will be invoked relative toPublisherSource.Subscriber.onNext(Object)
is undefined. If you need strict ordering seebeforeOnNext(Consumer)
andafterOnNext(Consumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
for (T t: resultOfThisPublisher()) { // NOTE: The order of operations here is not guaranteed by this method! processNext(t); onNext.accept(t); }
- Parameters:
onNext
- Invoked whenPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenOnComplete
Invokes theonComplete
Runnable
argument whenPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onComplete
will be invoked relative toPublisherSource.Subscriber.onComplete()
is undefined. If you need strict ordering seebeforeOnComplete(Runnable)
andafterOnComplete(Runnable)
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); // NOTE: The order of operations here is not guaranteed by this method! onSuccess.accept(results); nextOperation(results);
- Parameters:
onComplete
- Invoked whenPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenOnError
Invokes theonError
Consumer
argument whenPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onError
will be invoked relative toPublisherSource.Subscriber.onError(Throwable)
is undefined. If you need strict ordering seebeforeOnError(Consumer)
andafterOnError(Consumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch (Throwable cause) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(cause); onError.accept(cause); }
- Parameters:
onError
- Invoked beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenFinally
Invokes thewhenFinally
Runnable
argument exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.The order in which
whenFinally
will be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(Runnable)
andafterFinally(Runnable)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } finally { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.run(); }
- Parameters:
doFinally
- Invoked exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenFinally
Invokes the corresponding method onwhenFinally
TerminalSignalConsumer
argument when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.The order in which
whenFinally
will be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(TerminalSignalConsumer)
andafterFinally(TerminalSignalConsumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch(Throwable t) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();
- Parameters:
doFinally
- For each subscribe of the returnedPublisher
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Publisher
. - See Also:
-
whenRequest
Invokes theonRequest
LongConsumer
argument whenPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onRequest
- Invoked whenPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenCancel
Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedPublisher
.The order in which
whenFinally
will be invoked relative toCancellable.cancel()
is undefined. If you need strict ordering seebeforeCancel(Runnable)
andafterCancel(Runnable)
.- Parameters:
onCancel
- Invoked whenCancellable.cancel()
is called for Subscriptions of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
validateOutstandingDemand
Validate the outstanding demand (PublisherSource.Subscription.request(long)
minusPublisherSource.Subscriber.onNext(Object)
) does not go negative. This can be a useful diagnostic tool if custom operators or async sources are in use to ensure outstanding demand is always non-negative.Invalid
PublisherSource.Subscription.request(long)
maybe propagated by this operator, and is still the responsibility of upstream source to terminate in error.Here is pseudo-code demonstrating the functionality of this operator:
request(1); onNext(t1); onNext(t2); // throws an Exception because outstanding demand is 0
- Returns:
- The new
Publisher
. - See Also:
-
validateOutstandingDemand
public final Publisher<T> validateOutstandingDemand(ObjLongConsumer<T> onNextConsumer, LongBinaryConsumer requestConsumer) Validate the outstanding demand (PublisherSource.Subscription.request(long)
minusPublisherSource.Subscriber.onNext(Object)
) does not go negative. This can be a useful diagnostic tool if custom operators or async sources are in use to ensure outstanding demand is always non-negative.ReactiveStreams specification allows
PublisherSource.Subscriber
andPublisherSource.Subscription
to be concurrent, therefore the arguments of this function maybe invoked concurrently.Invalid
PublisherSource.Subscription.request(long)
maybe propagated by this operator, and is still the responsibility of upstream source to terminate in error.Here is pseudo-code demonstrating the functionality of this operator:
request(1); // calls requestConsumer(1, 1) onNext(t1); // calls onNextConsumer(t1, 0) onNext(t2); // calls onNextConsumer(t1, -1), throws an Exception because outstanding demand is 0
- Parameters:
onNextConsumer
- Called whenPublisherSource.Subscriber.onNext(Object)
is invoked with first argument is the signal and second argument is demand (after decrementing). This consumer is meant to be used for observability purposes, and is assumed to not throw.requestConsumer
- Called whenPublisherSource.Subscription.request(long)
is invoked with first argument ofn
and second argument of current demand (after incrementing). This method may only be called ifn
is valid. This consumer is meant to be used for observability purposes, and is assumed to not throw.- Returns:
- The new
Publisher
.
-
timeout
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.unit
- The units forduration
.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeout
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeout
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.unit
- The units forduration
.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeout
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeoutTerminal
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration during which the Publisher must complete.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. - See Also:
-
timeoutTerminal
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration during which the Publisher must complete.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. - See Also:
-
timeoutTerminal
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration during which the Publisher must complete.unit
- The units forduration
.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. - See Also:
-
timeoutTerminal
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration during which the Publisher must complete.unit
- The units forduration
.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between subscribe and termination. - See Also:
-
timeoutDemand
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.unit
- The units forduration
.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeoutDemand
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.unit
- The units forduration
.executor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeoutDemand
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
timeoutDemand
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.executor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
-
concat
Emits items emitted bynext
Publisher
afterthis
Publisher
terminates successfully.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); results.addAll(resultOfPublisher(next)); return results;
-
concat
Listens and emits the result ofnext
Single
afterthis
Publisher
terminates successfully.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); results.add(resultOfSingle(next)); return results;
-
concat
Listens for completion ofnext
Completable
afterthis
Publisher
terminates successfully. Any error fromthis
Publisher
andnext
Completable
is forwarded to the returnedPublisher
.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); resultOfCompletable(next); return results;
- Parameters:
next
-Completable
to wait for completion afterthis
Publisher
terminates successfully.- Returns:
- A
Publisher
that emits all items from thisPublisher
and then awaits successful completion ofnext
Completable
. - See Also:
-
concatPropagateCancel
This method is likeconcat(Completable)
exceptnext
will be subscribed to and cancelled if thisPublisher
is cancelled or terminates withPublisherSource.Subscriber.onError(Throwable)
.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); resultOfCompletable(next); return results;
- Parameters:
next
-Completable
to wait for completion afterthis
Publisher
terminates successfully. Will be subscribed to and cancelled if thisPublisher
is cancelled or terminates withPublisherSource.Subscriber.onError(Throwable)
.- Returns:
- A
Publisher
that emits all items from thisPublisher
and then awaits successful completion ofnext
Completable
. - See Also:
-
retry
Re-subscribes to thisPublisher
if an error is emitted and the passedBiIntPredicate
returnstrue
.This method may result in a
This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowError
if too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor
. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1, results); } else { throw cause; } } }
- Parameters:
shouldRetry
-BiIntPredicate
that given the retry count and the most recentThrowable
emitted from thisPublisher
determines if the operation should be retried.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted if the passedBiIntPredicate
returnedtrue
. - See Also:
-
retry
public final Publisher<T> retry(boolean terminateOnNextException, BiIntPredicate<Throwable> shouldRetry) Re-subscribes to thisPublisher
if an error is emitted and the passedBiIntPredicate
returnstrue
.This method may result in a
This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowError
if too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor
. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (!terminateOnNextException && shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1, results); } else { throw cause; } } }
- Parameters:
terminateOnNextException
-true
means that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)
will be caught, cancel thePublisherSource.Subscription
, propagate aPublisherSource.Subscriber.onError(Throwable)
downstream, and no retry will be attempted.false
means that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)
will NOT be caught and will propagate upstream. May lead to incorrect demand accounting and "hangs" if this operator isn't the last in the chain.
shouldRetry
-BiIntPredicate
that given the retry count and the most recentThrowable
emitted from thisPublisher
determines if the operation should be retried.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted if the passedBiIntPredicate
returnedtrue
. - See Also:
-
retryWhen
Re-subscribes to thisPublisher
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedPublisher
terminates with that error.This method may result in a
This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowError
if too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor
. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1, results); } catch (Throwable ignored) { throw cause; } } }
- Parameters:
retryWhen
-BiIntFunction
that given the retry count and the most recentThrowable
emitted from thisPublisher
returns aCompletable
. If thisCompletable
emits an error, that error is emitted from the returnedPublisher
, otherwise, originalPublisher
is re-subscribed when thisCompletable
completes.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted andCompletable
returned byBiIntFunction
completes successfully. - See Also:
-
retryWhen
public final Publisher<T> retryWhen(boolean terminateOnNextException, BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisPublisher
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedPublisher
terminates with that error.This method may result in a
This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowError
if too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor
. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (terminateOnNextException) { throw cause; } try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1, results); } catch (Throwable ignored) { throw cause; } } }
- Parameters:
terminateOnNextException
-true
means that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)
will be caught, cancel thePublisherSource.Subscription
, propagate aPublisherSource.Subscriber.onError(Throwable)
downstream, and no retry will be attempted.false
means that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)
will NOT be caught and will propagate upstream. May lead to incorrect demand accounting and "hangs" if this operator isn't the last in the chain.
retryWhen
-BiIntFunction
that given the retry count and the most recentThrowable
emitted from thisPublisher
returns aCompletable
. If thisCompletable
emits an error, that error is emitted from the returnedPublisher
, otherwise, originalPublisher
is re-subscribed when thisCompletable
completes.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted andCompletable
returned byBiIntFunction
completes successfully. - See Also:
-
repeat
Re-subscribes to thisPublisher
when it completes and the passedIntPredicate
returnstrue
.This method may result in a
This method provides a means to repeat an operation multiple times and in sequential programming is similar to:StackOverflowError
if too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor
. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
List<T> results = new ...; int i = 0; do { results.addAll(resultOfThisPublisher()); } while (shouldRepeat.test(++i)); return results;
- Parameters:
shouldRepeat
-IntPredicate
that given the repeat count determines if the operation should be repeated.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes when it completes if the passedIntPredicate
returnstrue
. - See Also:
-
repeatWhen
Re-subscribes to thisPublisher
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedPublisher
is completed.This method may result in a
This method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:StackOverflowError
if too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor
. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())
List<T> results = new ...; int i = 0; while (true) { results.addAll(resultOfThisPublisher()); try { repeatWhen.apply(++i); // Either throws or completes normally } catch (Throwable cause) { break; } } return results;
- Parameters:
repeatWhen
-IntFunction
that given the repeat count returns aCompletable
. If thisCompletable
emits an error repeat is terminated, otherwise, originalPublisher
is re-subscribed when thisCompletable
completes.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted andCompletable
returned byIntFunction
completes successfully. - See Also:
-
skipWhile
Skip items emitted by thisPublisher
until the first time the predicate is not satisfied.This method provides a data transformation in sequential programming similar to:
List<T> results = ...; boolean skipping = true; for (T t : resultOfThisPublisher()) { if (skipping) { skipping = predicate.test(t); } if (!skipping) { results.add(t); } } return results;
- Parameters:
predicate
- for evaluating whether to continue skipping items.- Returns:
- A
Publisher
that skips items until the predicate returns falsepredicate
. - See Also:
-
takeAtMost
Takes at mostnumElements
elements fromthis
Publisher
.If no terminal event is received before receiving
numElements
elements,PublisherSource.Subscription
for thePublisherSource.Subscriber
is cancelled.This method provides a means to take a limited number of results from this
Publisher
and in sequential programming is similar to:List<T> results = ...; int i = 0; for (T t : resultOfThisPublisher()) { if (++i > numElements) { break; } results.add(t); } return results;
-
takeWhile
Takes elements whilePredicate
istrue
and then cancelPublisherSource.Subscription
of thisPublisher
once it returnsfalse
.This method provides a means to take a limited number of results from this
Publisher
and in sequential programming is similar to:List<T> results = ...; for (T t : resultOfThisPublisher()) { if (!predicate.test(result)) { break; } results.add(t); } return results;
- Parameters:
predicate
-Predicate
that is checked before emitting any item to aPublisherSource.Subscriber
. If this predicate returnstrue
, that item is emitted, elsePublisherSource.Subscription
is cancelled.- Returns:
- A
Publisher
that only emits the items as long as thePredicate.test(Object)
method returnstrue
. - See Also:
-
takeUntil
Takes elements untilCompletable
is terminated successfully or with failure.This method provides a means to take a limited number of results from this
Publisher
and in sequential programming is similar to:List<T> results = ...; for (T t : resultOfThisPublisher()) { if (isCompleted(until)) { break; } takeResults.add(t); } return results;
- Parameters:
until
-Completable
, termination of which, terminates the returnedPublisher
. If thisPublisher
maybe resubscribed theCompletable
should be also, or usedefer(Supplier)
to create a newCompletable
on each subscribe.- Returns:
- A
Publisher
that only emits the items tilluntil
Completable
is completed. - See Also:
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T, ? extends Key> keySelector) Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s. Item to group association is done bykeySelector
Function
. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriber
has not yet cancelled itsPublisherSource.Subscription
, this item is sent to thatPublisherSource.Subscriber
. Otherwise a newGroupedPublisher
is created and emitted from the returnedPublisher
.Flow control
Multiple
PublisherSource.Subscriber
s (for multipleGroupedPublisher
s) request items individually from thisPublisher
. Since, there is no way for aPublisherSource.Subscriber
to only request elements for its group, elements requested by one group may end up producing items for a different group, which has not yet requested enough. This will cause items to be queued per group which can not be emitted due to lack of demand. This queue size can be controlled viagroupBy(Function, int)
.Cancellation
If the
PublisherSource.Subscriber
of the returnedPublisher
cancels itsPublisherSource.Subscription
, and there are no activeGroupedPublisher
sPublisherSource.Subscriber
s then upstream will be cancelled.PublisherSource.Subscriber
s of individualGroupedPublisher
s can cancel theirPublisherSource.Subscription
s at any point. If any new item is emitted for the cancelledGroupedPublisher
, a newGroupedPublisher
will be emitted from the returnedPublisher
. Any queued items for a cancelledPublisherSource.Subscriber
for aGroupedPublisher
will be discarded and hence will not be emitted if the sameGroupedPublisher
is emitted again.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Key k = keySelector.apply(result); List<T> v = results.get(k); if (v == null) { v = // new List results.put(k, v); } v.add(result); } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to aGroupedPublisher
.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T, ? extends Key> keySelector, int queueLimit) Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s. Item to group association is done bykeySelector
Function
. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriber
has not yet cancelled itsPublisherSource.Subscription
, this item is sent to thatPublisherSource.Subscriber
. Otherwise a newGroupedPublisher
is created and emitted from the returnedPublisher
.Flow control
Multiple
PublisherSource.Subscriber
s (for multipleGroupedPublisher
s) request items individually from thisPublisher
. Since, there is no way for aPublisherSource.Subscriber
to only request elements for its group, elements requested by one group may end up producing items for a different group, which has not yet requested enough. This will cause items to be queued per group which can not be emitted due to lack of demand. This queue size can be controlled with thequeueLimit
argument.Cancellation
If the
PublisherSource.Subscriber
of the returnedPublisher
cancels itsPublisherSource.Subscription
, and there are no activeGroupedPublisher
sPublisherSource.Subscriber
s then upstream will be cancelled.PublisherSource.Subscriber
s of individualGroupedPublisher
s can cancel theirPublisherSource.Subscription
s at any point. If any new item is emitted for the cancelledGroupedPublisher
, a newGroupedPublisher
will be emitted from the returnedPublisher
. Any queued items for a cancelledPublisherSource.Subscriber
for aGroupedPublisher
will be discarded and hence will not be emitted if the sameGroupedPublisher
is emitted again.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Key k = keySelector.apply(result); List<T> v = results.get(k); if (v == null) { v = // new List results.put(k, v); } v.add(result); } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to aGroupedPublisher
.queueLimit
- The number of elements which will be queued for each groupedPublisherSource.Subscriber
in order to compensate for unequal demand. This also applies to the returnedPublisher
which may also have to queue signals.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T, ? extends Key> keySelector, int queueLimit, int expectedGroupCountHint) Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s. Item to group association is done bykeySelector
Function
. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriber
has not yet cancelled itsPublisherSource.Subscription
, this item is sent to thatPublisherSource.Subscriber
. Otherwise a newGroupedPublisher
is created and emitted from the returnedPublisher
.Flow control
Multiple
PublisherSource.Subscriber
s (for multipleGroupedPublisher
s) request items individually from thisPublisher
. Since, there is no way for aPublisherSource.Subscriber
to only request elements for its group, elements requested by one group may end up producing items for a different group, which has not yet requested enough. This will cause items to be queued per group which can not be emitted due to lack of demand. This queue size can be controlled with thequeueLimit
argument.Cancellation
If the
PublisherSource.Subscriber
of the returnedPublisher
cancels itsPublisherSource.Subscription
, and there are no activeGroupedPublisher
sPublisherSource.Subscriber
s then upstream will be cancelled.PublisherSource.Subscriber
s of individualGroupedPublisher
s can cancel theirPublisherSource.Subscription
s at any point. If any new item is emitted for the cancelledGroupedPublisher
, a newGroupedPublisher
will be emitted from the returnedPublisher
. Any queued items for a cancelledPublisherSource.Subscriber
for aGroupedPublisher
will be discarded and hence will not be emitted if the sameGroupedPublisher
is emitted again.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Key k = keySelector.apply(result); List<T> v = results.get(k); if (v == null) { v = // new List results.put(k, v); } v.add(result); } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to aGroupedPublisher
.queueLimit
- The number of elements which will be queued for each groupedPublisherSource.Subscriber
in order to compensate for unequal demand. This also applies to the returnedPublisher
which may also have to queue signals.expectedGroupCountHint
- Expected number of groups that would be emitted bythis
Publisher
. This is just a hint for internal data structures and does not have to be precise.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
-
groupToMany
public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit) The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Iterator<Key> keys = keySelector.apply(result); for (Key key : keys) { List<T> v = results.get(key); if (v == null) { v = // new List results.put(key, v); } v.add(result); } } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to multipleGroupedPublisher
s.queueLimit
- The number of elements which will be queued for each groupedPublisherSource.Subscriber
in order to compensate for unequal demand. This also applies to the returnedPublisher
which may also have to queue signals.Publisher
returned from this method not requesting enough viaPublisherSource.Subscription.request(long)
.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
-
groupToMany
public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit, int expectedGroupCountHint) The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Iterator<Key> keys = keySelector.apply(result); for (Key key : keys) { List<T> v = results.get(key); if (v == null) { v = // new List results.put(key, v); } v.add(result); } } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to multipleGroupedPublisher
s.queueLimit
- The number of elements which will be queued for each groupedPublisherSource.Subscriber
in order to compensate for unequal demand. This also applies to the returnedPublisher
which may also have to queue signals.expectedGroupCountHint
- Expected number of groups that would be emitted bythis
Publisher
. This is just a hint for internal data structures and does not have to be precise.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
-
multicastToExactly
Deprecated.Usemulticast(int)
.Create aPublisher
that multicasts all the signals to exactlyexpectedSubscribers
.Depending on
PublisherSource.Subscription.request(long)
demand it is possible that data maybe queued before being delivered to eachPublisherSource.Subscriber
! For example if there are 2PublisherSource.Subscriber
s and the first callsrequest(10)
, and the second only callsrequest(1)
, then 9 elements will be queued to deliver to second when morePublisherSource.Subscription.request(long)
demand is made.In sequential programming this is similar to the following:
List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
-
multicastToExactly
Deprecated.Usemulticast(int, int)
.Create aPublisher
that allows exactlyexpectedSubscribers
subscribes. The events from thisPublisher
object will be delivered to eachPublisherSource.Subscriber
.Depending on
PublisherSource.Subscription.request(long)
demand it is possible that data maybe queued before being delivered to eachPublisherSource.Subscriber
! For example if there are 2PublisherSource.Subscriber
s and the first callsrequest(10)
, and the second only callsrequest(1)
, then 9 elements will be queued to deliver to second when morePublisherSource.Subscription.request(long)
demand is made.In sequential programming this is similar to the following:
List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
expectedSubscribers
- The number of expected subscribe calls required on the returnedPublisher
before subscribing to thisPublisher
.queueLimit
- The number of elements which will be queued for eachPublisherSource.Subscriber
in order to compensate for unequal demand.- Returns:
- a
Publisher
that allows exactlyexpectedSubscribers
subscribes.
-
multicast
Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
.Downstream
PublisherSource.Subscriber
s may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscriber
subscribed will not be queued.Upstream outstanding
Subscription demand
may be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscriber
s will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscriber
subscribe to the return value.- Returns:
- a
Publisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
. - See Also:
-
multicast
Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
.Downstream
PublisherSource.Subscriber
s may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscriber
subscribed will not be queued.Upstream outstanding
Subscription demand
may be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscriber
s will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscriber
subscribe to the return value.cancelUpstream
-true
if upstream should becancelled
when all downstreamPublisherSource.Subscriber
s cancel.false
means that cancel will not be propagated upstream even if all downstreamPublisherSource.Subscriber
s cancel, and the upstream Subscription will stay valid until termination.- Returns:
- a
Publisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
. - See Also:
-
multicast
Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
.Downstream
PublisherSource.Subscriber
s may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscriber
subscribed will not be queued.Upstream outstanding
Subscription demand
may be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscriber
s will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscriber
subscribe to the return value.queueLimit
- The number of elements which will be queued for eachPublisherSource.Subscriber
in order to compensate for unequal demand.- Returns:
- a
Publisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
. - See Also:
-
multicast
Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
.Downstream
PublisherSource.Subscriber
s may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscriber
subscribed will not be queued.Upstream outstanding
Subscription demand
may be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscriber
s will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscriber
subscribe to the return value.queueLimit
- The number of elements which will be queued for eachPublisherSource.Subscriber
in order to compensate for unequal demand.cancelUpstream
-true
if upstream should becancelled
when all downstreamPublisherSource.Subscriber
s cancel.false
means that cancel will not be propagated upstream even if all downstreamPublisherSource.Subscriber
s cancel, and the upstream Subscription will stay valid until termination.- Returns:
- a
Publisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
. - See Also:
-
multicast
public final Publisher<T> multicast(int minSubscribers, int queueLimit, Function<Throwable, Completable> terminalResubscribe) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
.Downstream
PublisherSource.Subscriber
s may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscriber
subscribed will not be queued.Upstream outstanding
Subscription demand
may be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscriber
s will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscriber
subscribe to the return value.queueLimit
- The number of elements which will be queued for eachPublisherSource.Subscriber
in order to compensate for unequal demand.terminalResubscribe
- AFunction
that is invoked when a terminal signal arrives from upstream, and returns aCompletable
whose termination resets the state of the returnedPublisher
and allows for downstream resubscribing. The argument to this function is as follows:null
if upstream terminates withPublisherSource.Subscriber.onComplete()
- otherwise the
Throwable
fromPublisherSource.Subscriber.onError(Throwable)
- Returns:
- a
Publisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
. - See Also:
-
multicast
public final Publisher<T> multicast(int minSubscribers, int queueLimit, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aPublisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
.Downstream
PublisherSource.Subscriber
s may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscriber
subscribed will not be queued.Upstream outstanding
Subscription demand
may be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscriber
s will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
minSubscribers
- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscriber
subscribe to the return value.queueLimit
- The number of elements which will be queued for eachPublisherSource.Subscriber
in order to compensate for unequal demand.cancelUpstream
-true
if upstream should becancelled
when all downstreamPublisherSource.Subscriber
s cancel.false
means that cancel will not be propagated upstream even if all downstreamPublisherSource.Subscriber
s cancel, and the upstream Subscription will stay valid until termination.terminalResubscribe
- AFunction
that is invoked when a terminal signal arrives from upstream, and returns aCompletable
whose termination resets the state of the returnedPublisher
and allows for downstream resubscribing. The argument to this function is as follows:null
if upstream terminates withPublisherSource.Subscriber.onComplete()
- otherwise the
Throwable
fromPublisherSource.Subscriber.onError(Throwable)
- Returns:
- a
Publisher
that subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscriber
s. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber
. - See Also:
-
replay
Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but also retainshistory
of the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)
which are emitted to new downstreamPublisherSource.Subscriber
s before emitting new signals.- Parameters:
history
- max number of signals (excludingPublisherSource.Subscriber.onComplete()
andPublisherSource.Subscriber.onError(Throwable)
) to retain.- Returns:
- A
Publisher
that allows for multiple downstream subscribers and emits the previoushistory
PublisherSource.Subscriber.onNext(Object)
signals to each new subscriber. - See Also:
-
replay
Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but also retainshistoryHint
of the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)
which are emitted to new downstreamPublisherSource.Subscriber
s before emitting new signals. Each item is only retained forttl
duration of time.- Parameters:
historyHint
- hint for max number of signals (excludingPublisherSource.Subscriber.onComplete()
andPublisherSource.Subscriber.onError(Throwable)
) to retain. Due to concurrency between threads (timer, accumulation, subscribe) the maximum number of signals delivered to new subscribers may potentially be more but this hint provides a general bound for memory when concurrency subsides.ttl
- duration each element will be retained before being removed.executor
- used to enforce thettl
argument.- Returns:
- A
Publisher
that allows for multiple downstream subscribers and emits the previoushistoryHint
PublisherSource.Subscriber.onNext(Object)
signals to each new subscriber. - See Also:
-
replay
Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but will also retain some history ofPublisherSource.Subscriber.onNext(Object)
signals according to theReplayAccumulator
accumulatorSupplier
.- Parameters:
accumulatorSupplier
- supplies aReplayAccumulator
on each subscribe to upstream that can retain history ofPublisherSource.Subscriber.onNext(Object)
signals to deliver to new downstream subscribers.- Returns:
- A
Publisher
that allows for multiple downstream subscribers that can retain history ofPublisherSource.Subscriber.onNext(Object)
signals to deliver to new downstream subscribers. - See Also:
-
replay
Similar tomulticast(int)
in that multiple downstreamPublisherSource.Subscriber
s are enabled on the returnedPublisher
but will also retain some history ofPublisherSource.Subscriber.onNext(Object)
signals according to theReplayStrategy
replayStrategy
.- Parameters:
replayStrategy
- aReplayStrategy
that determines the replay behavior and history retention logic.- Returns:
- A
Publisher
that allows for multiple downstream subscribers that can retain history ofPublisherSource.Subscriber.onNext(Object)
signals to deliver to new downstream subscribers. - See Also:
-
buffer
public final <BC extends BufferStrategy.Accumulator<T,B>, Publisher<B> bufferB> (BufferStrategy<T, BC, B> strategy) Create aPublisher
that buffers items from thisPublisher
and emit those buffers instead of the individual items.In sequential programming this is similar to the following:
Notes:List accumulators = strategy.boundaries(); List buffers = ...; BC currentAccumulator; for (T t : resultOfThisPublisher()) { // This is an approximation; accumulators are emitted asynchronously. BC nextAccumulator = accumulators.remove(0).get(); buffers.add(currentAccumulator.finish()); currentAccumulator = nextAccumulator; currentAccumulator.add(t); } return buffers;
- If this
Publisher
does not emit items within theboundary
, it's expected it will emit an emptyaccumulated value
as the result of accumulating nothing. Usefilter(Predicate)
operator if empty accumulations have to be discarded. - If more than one
boundary
is emitted while this operatoraccumulates
or emits thenext
result of accumulation, those boundaries will be discarded without invokingBufferStrategy.Accumulator.finish()
method.
- Type Parameters:
BC
- Type of theBufferStrategy.Accumulator
to buffer items from thisPublisher
.B
- Type of the buffer emitted from the returnedPublisher
.- Parameters:
strategy
- ABufferStrategy
to use for buffering items from thisPublisher
.- Returns:
- a
Publisher
that buffers items from thisPublisher
and emit those buffers instead of the individual items. - See Also:
- If this
-
beforeOnSubscribe
public final Publisher<T> beforeOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribe
Consumer
argument beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
onSubscribe
- Invoked beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeOnNext
Invokes theonNext
Consumer
argument beforePublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); for (T result : results) { onNext.accept(result); } nextOperation(results);
- Parameters:
onNext
- Invoked beforePublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeOnError
Invokes theonError
Consumer
argument beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch (Throwable cause) { onError.accept(cause); nextOperation(cause); }
- Parameters:
onError
- Invoked beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeOnComplete
Invokes theonComplete
Runnable
argument beforePublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); onComplete.run(); nextOperation(results);
- Parameters:
onComplete
- Invoked beforePublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeRequest
Invokes theonRequest
LongConsumer
argument beforePublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onRequest
- Invoked beforePublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeCancel
Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onCancel
- Invoked beforeCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeFinally
Invokes thebeforeFinally
Runnable
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } finally { doFinally.run(); nextOperation(); // Maybe notifying of cancellation, or termination }
- Parameters:
doFinally
- Invoked before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeFinally
Invokes the corresponding method onbeforeFinally
TerminalSignalConsumer
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch(Throwable t) { doFinally.onError(t); nextOperation(); // Maybe notifying of cancellation, or termination return; } doFinally.onComplete(); nextOperation(); // Maybe notifying of cancellation, or termination
- Parameters:
doFinally
- For each subscribe of the returnedPublisher
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Publisher
. - See Also:
-
beforeSubscriber
public final Publisher<T> beforeSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscriber
methods before thePublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newPublisherSource.Subscriber
on each call to subscribe and invokes all thePublisherSource.Subscriber
methods before thePublisherSource.Subscriber
s of the returnedPublisher
.PublisherSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
beforeSubscription
public final Publisher<T> beforeSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscription
methods before thePublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
subscriptionSupplier
- Creates a newPublisherSource.Subscription
on each call to subscribe and invokes all thePublisherSource.Subscription
methods before thePublisherSource.Subscription
s of the returnedPublisher
.PublisherSource.Subscription
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterOnSubscribe
public final Publisher<T> afterOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribe
Consumer
argument afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
onSubscribe
- Invoked afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterOnNext
Invokes theonNext
Consumer
argument afterPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); nextOperation(results); for (T result : results) { onNext.accept(result); }
- Parameters:
onNext
- Invoked afterPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterOnError
Invokes theonError
Consumer
argument afterPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch (Throwable cause) { nextOperation(cause); onError.accept(cause); }
- Parameters:
onError
- Invoked afterPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterOnComplete
Invokes theonComplete
Runnable
argument afterPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); nextOperation(results); onComplete.run();
- Parameters:
onComplete
- Invoked afterPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterRequest
Invokes theonRequest
LongConsumer
argument afterPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onRequest
- Invoked afterPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterCancel
Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onCancel
- Invoked afterCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterFinally
Invokes theafterFinally
Runnable
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } finally { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.run(); }
- Parameters:
doFinally
- Invoked after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
afterFinally
Invokes the corresponding method onafterFinally
TerminalSignalConsumer
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch(Throwable t) { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();
- Parameters:
doFinally
- For each subscribe of the returnedPublisher
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Publisher
. - See Also:
-
afterSubscriber
public final Publisher<T> afterSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscriber
methods after thePublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newPublisherSource.Subscriber
for each new subscribe and invokes all thePublisherSource.Subscriber
methods after thePublisherSource.Subscriber
s of the returnedPublisher
.PublisherSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenSubscriber
public final Publisher<T> whenSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes methods on thatPublisherSource.Subscriber
when the corresponding methods are called forPublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newPublisherSource.Subscriber
for each new subscribe and invokes methods on thatPublisherSource.Subscriber
when the corresponding methods are called forPublisherSource.Subscriber
s of the returnedPublisher
.PublisherSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Publisher
.
-
afterSubscription
public final Publisher<T> afterSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods after thePublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
subscriptionSupplier
- Creates a newPublisherSource.Subscription
for each new subscribe and invokes all thePublisherSource.Subscription
methods after thePublisherSource.Subscription
s of the returnedPublisher
.PublisherSource.Subscription
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
whenSubscription
public final Publisher<T> whenSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods when the corresponding methods are called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
subscriptionSupplier
- Creates a newPublisherSource.Subscription
for each new subscribe and invokes all thePublisherSource.Subscription
methods when thePublisherSource.Subscription
s of the returnedPublisher
.PublisherSource.Subscription
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
-
forEach
Subscribes to thisPublisher
and invokesforEach
Consumer
for each item emitted by thisPublisher
.This will request
Long.MAX_VALUE
from thePublisherSource.Subscription
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); results.iterator().forEachRemaining(forEach);
- Parameters:
forEach
-Consumer
to invoke for eachPublisherSource.Subscriber.onNext(Object)
.- Returns:
Cancellable
used to invokeCancellable.cancel()
on the parameter ofPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
for thisPublisher
.
-
publishOn
Creates a newPublisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
publishOn(io.servicetalk.concurrent.Executor, BooleanSupplier)
, current operator always enforces offloading to the passedExecutor
.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods. - See Also:
-
publishOn
Creates a newPublisher
that may use the passedExecutor
to invoke allPublisherSource.Subscriber
methods. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
publishOn(io.servicetalk.concurrent.Executor)
, current operator may skip offloading to the passedExecutor
, depending on the result of theBooleanSupplier
hint.- Parameters:
executor
-Executor
to use.shouldOffload
- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalse
is returned in order to preserve signal ordering.- Returns:
- A new
Publisher
that may use the passedExecutor
to invoke allPublisherSource.Subscriber
methods. - See Also:
-
subscribeOn
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods:- All
PublisherSource.Subscription
methods. - The
handleSubscribe(PublisherSource.Subscriber)
method.
Executor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
subscribeOn(io.servicetalk.concurrent.Executor, BooleanSupplier)
, current operator always enforces offloading to the passedExecutor
.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke all methods ofPublisherSource.Subscription
andhandleSubscribe(PublisherSource.Subscriber)
. - See Also:
- All
-
subscribeOn
Creates a newPublisher
that may use the passedExecutor
to invoke the following methods:- All
PublisherSource.Subscription
methods. - The
handleSubscribe(PublisherSource.Subscriber)
method.
Executor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
.Note: unlike
subscribeOn(io.servicetalk.concurrent.Executor)
, current operator may skip offloading to the passedExecutor
, depending on the result of theBooleanSupplier
hint.- Parameters:
executor
-Executor
to use.shouldOffload
- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalse
is returned in order to preserve signal ordering.- Returns:
- A new
Publisher
that may use the passedExecutor
to invoke all methods ofPublisherSource.Subscription
andhandleSubscribe(PublisherSource.Subscriber)
. - See Also:
- All
-
setContextOnSubscribe
Specify theContextMap
to use forAsyncContext
when the returnedPublisher
is subscribed to.This operator only impacts behavior if the returned
Publisher
is subscribed directly after this operator, that means this must be the "last operator" in the chain for this to have an impact.- Parameters:
context
- TheContextMap
to use forAsyncContext
when subscribed.- Returns:
- A
Completable
that will use theContextMap
forAsyncContext
when subscribed.
-
liftSync
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Publisher
which when subscribed, theoperator
argument will be used to wrap thePublisherSource.Subscriber
before subscribing to thisPublisher
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .filter(..) // B
original -> modified
"operator" MUST be "synchronous" in that it does not interact with the originalPublisherSource.Subscriber
from outside the modifiedPublisherSource.Subscriber
orPublisherSource.Subscription
threads. That is to say this operator will not impact theExecutor
constraints already in place between A and B above. If you need asynchronous behavior, or are unsure, seeliftAsync(PublisherOperator)
.- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
operator
- The custom operator logic. The input is the "original"PublisherSource.Subscriber
to thisPublisher
and the return is the "modified"PublisherSource.Subscriber
that provides custom operator business logic.- Returns:
- a
Publisher
which when subscribed, theoperator
argument will be used to wrap thePublisherSource.Subscriber
before subscribing to thisPublisher
. - See Also:
-
liftSyncToSingle
public final <R> Single<R> liftSyncToSingle(PublisherToSingleOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Single
which when subscribed, theoperator
argument will be used to convert between theSingleSource.Subscriber
to aPublisherSource.Subscriber
before subscribing to thisPublisher
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .filter(..) // B - we have converted to Single now!
original -> modified
"operator" MUST be "synchronous" in that it does not interact with the originalPublisherSource.Subscriber
from outside the modifiedPublisherSource.Subscriber
orPublisherSource.Subscription
threads. That is to say this operator will not impact theExecutor
constraints already in place between A and B above. If you need asynchronous behavior, or are unsure, don't use this operator.- Type Parameters:
R
- Type of the items emitted by the returnedSingle
.- Parameters:
operator
- The custom operator logic. The input is the "original"SingleSource.Subscriber
to the returnedSingle
and the return is the "modified"PublisherSource.Subscriber
that provides custom operator business logic on thisPublisher
.- Returns:
- a
Single
which when subscribed, theoperator
argument will be used to convert theSingleSource.Subscriber
to aPublisherSource.Subscriber
before subscribing to thisPublisher
.
-
liftAsync
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Publisher
which will wrap thePublisherSource.Subscriber
using the providedoperator
argument before subscribing to thisPublisher
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftAsync(original -> modified) .filter(..) // B
original -> modified
"operator" MAY be "asynchronous" in that it may interact with the originalPublisherSource.Subscriber
from outside the modifiedPublisherSource.Subscriber
orPublisherSource.Subscription
threads. More specifically:- all of the
PublisherSource.Subscriber
invocations going "downstream" (i.e. from A to B above) MAY be offloaded via anExecutor
- all of the
PublisherSource.Subscription
invocations going "upstream" (i.e. from B to A above) MAY be offloaded via anExecutor
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
operator
- The custom operator logic. The input is the "original"PublisherSource.Subscriber
to thisPublisher
and the return is the "modified"PublisherSource.Subscriber
that provides custom operator business logic.- Returns:
- a
Publisher
which when subscribed, theoperator
argument will be used to wrap thePublisherSource.Subscriber
before subscribing to thisPublisher
. - See Also:
- all of the
-
firstOrElse
Converts thisPublisher
to aSingle
.This operator is useful if the
Publisher
that is being converted is potentially empty (in which case thedefaultValueSupplier
will be triggered) or may emit multiple elements (in which case it will be cancelled after receiving the first element). If a conversion toSingle
is needed where it is expected that thePublisher
returns exactly one element, consider usingfirstOrError()
instead.- Parameters:
defaultValueSupplier
- ASupplier
of default value if thisPublisher
did not emit any item.- Returns:
- A
Single
that will contain the first item emitted from the thisPublisher
. If the sourcePublisher
does not emit any item, then the returnedSingle
will contain the value as returned by the passedSupplier
. - See Also:
-
firstOrError
Converts thisPublisher
to aSingle
and ensures that it emits exactly a singleelement
before completion.This operator ensures that the
Publisher
emits exactly a singlePublisherSource.Subscriber.onNext(Object)
to itsPublisherSource.Subscriber
. If thisPublisher
terminates without emitting any items aNoSuchElementException
will be signaled and if thisPublisher
emits more than one item, anIllegalArgumentException
will be signaled. Any error emitted by thisPublisher
will be forwarded to the returnedSingle
.To uphold the guarantees laid out in the previous paragraph, this operator requests two items from the
Publisher
. This means that if thePublisher
does not complete after signaling one element, this operator will not complete. If "one element and then complete" semantics are desired, consider chaining thetakeAtMost(1)
operator beforehand. This will ensure a completion signal after one item is propagated from thePublisher
.- Returns:
- A
Single
that will contain the first item emitted from the thisPublisher
. If the sourcePublisher
does not emit any item, then the returnedSingle
will terminate withNoSuchElementException
. - See Also:
-
ignoreElements
Ignores all elements emitted by thisPublisher
and forwards the termination signal to the returnedCompletable
.- Returns:
- A
Completable
that mirrors the terminal signal from thisPublisher
. - See Also:
-
completableOrError
Converts thisPublisher
to aCompletable
. If thisPublisher
emits anyPublisherSource.Subscriber.onNext(Object)
signals the resultingCompletable
will be terminated with aIllegalArgumentException
.- Returns:
- A
Completable
that mirrors the terminal signal from thisPublisher
, and terminates in error if anPublisherSource.Subscriber.onNext(Object)
signals.
-
collect
public final <R> Single<R> collect(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> collector) Collects all items emitted by thisPublisher
into a single item.- Type Parameters:
R
- Type of the reduced item.- Parameters:
resultFactory
- Factory for the result which collects all items emitted by thisPublisher
. This will be called every time the returnedSingle
is subscribed.collector
- Invoked for every item emitted by the sourcePublisher
and returns the same or alteredresult
object.- Returns:
- A
Single
that completes with the singleresult
or any error emitted by the sourcePublisher
. - See Also:
-
toFuture
Convert thisPublisher
into aFuture
with aCollection
containing the elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediateCollection
will be discarded and theFuture
will complete exceptionally.- Returns:
- a
Future
with aCollection
containing the elements of thisPublisher
upon successful termination. - See Also:
-
toFuture
public final <R> Future<R> toFuture(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) Convert thisPublisher
into aFuture
of typePublisher
which represents all elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediatePublisher
will be discarded and theFuture
will complete exceptionally.- Type Parameters:
R
- Type of the reduced item.- Parameters:
resultFactory
- Factory for the result which collects all items emitted by thisPublisher
.reducer
- Invoked for every item emitted by the sourcePublisher
and returns the same or alteredresult
object.- Returns:
- a
Future
of typePublisher
which represents all elements of thisPublisher
upon successful termination.
-
toCompletionStage
Convert thisPublisher
into aCompletionStage
with aCollection
containing the elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediateCollection
will be discarded and theCompletionStage
will complete exceptionally.- Returns:
- a
CompletionStage
with aCollection
containing the elements of thisPublisher
upon successful termination. - See Also:
-
toCompletionStage
public final <R> CompletionStage<R> toCompletionStage(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) Convert thisPublisher
into aCompletionStage
of typePublisher
which represents all elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediatePublisher
will be discarded and theCompletionStage
will complete exceptionally.- Type Parameters:
R
- Type of the reduced item.- Parameters:
resultFactory
- Factory for the result which collects all items emitted by thisPublisher
.reducer
- Invoked for every item emitted by the sourcePublisher
and returns the same or alteredresult
object.- Returns:
- a
CompletionStage
of typePublisher
which represents all elements of thisPublisher
upon successful termination.
-
toInputStream
Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required. If the returnedInputStream
is closed,PublisherSource.Subscription
is cancelled and any unread data is disposed.- Any items received by
PublisherSource.Subscriber.onNext(Object)
are converted to abyte[]
using the passedserializer
. Thesebyte
s are available to be read from theInputStream
- Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in anIOException
) when data is read from the returnedInputStream
. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedInputStream
's read methods will return-1
to indicate end of stream after emitting all received data.
Flow control
This operator may pre-fetch may pre-fetch items fromthis
Publisher
if available to reduce blocking for read operations from the returnedInputStream
. In order to increase responsiveness of theInputStream
some amount of buffering may be done. UsetoInputStream(Function, int)
to manage capacity of this buffer.- Parameters:
serializer
-Function
that is invoked for every item emitted bythis
Publisher
.- Returns:
InputStream
that emits all data emitted bythis
Publisher
. Ifthis
Publisher
terminates with an error, same error is thrown (wrapped in anIOException
) from the returnedInputStream
s read methods after emitting all received data.
-
toInputStream
Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required. If the returnedInputStream
is closed,PublisherSource.Subscription
is cancelled and any unread data is disposed.- Any items received by
PublisherSource.Subscriber.onNext(Object)
are converted to abyte[]
using the passedserializer
. Thesebyte
s are available to be read from theInputStream
- Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in anIOException
) when data is read from the returnedInputStream
. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedInputStream
's read methods will return-1
to indicate end of stream after emitting all received data.
Flow control
This operator may pre-fetch items fromthis
Publisher
if available to reduce blocking for read operations from the returnedInputStream
. In order to increase responsiveness of theInputStream
some amount of buffering may be done.queueCapacity
can be used to bound this buffer.- Parameters:
serializer
-Function
that is invoked for every item emitted bythis
Publisher
.queueCapacity
- Hint for the capacity of the intermediary queue that stores items that are emitted bythis
Publisher
but has not yet been read from the returnedInputStream
.- Returns:
InputStream
that emits all data emitted bythis
Publisher
. Ifthis
Publisher
terminates with an error, same error is thrown (wrapped in anIOException
) from the returnedInputStream
s read methods after emitting all received data.
-
toIterable
Convertsthis
Publisher
to anBlockingIterable
. Every timeBlockingIterable.iterator()
is called on the returnedBlockingIterable
,this
Publisher
is subscribed following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.- Any items received by
PublisherSource.Subscriber.onNext(Object)
is returned from a call toBlockingIterator.next()
. - Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in aRuntimeException
if required) whenBlockingIterator.next()
is called. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedBlockingIterator
sIterator.hasNext()
will returnfalse
BlockingIterator.next()
will throwNoSuchElementException
. This error will be thrown only after draining all queued data, if any.
Flow control
This operator may pre-fetch items fromthis
Publisher
if available to reduce blocking ofIterator.hasNext()
from the returnedBlockingIterable
. In order to increase responsiveness of theIterator
some amount of buffering may be done. UsetoIterable(int)
to manage capacity of this buffer.Blocking
The returnedBlockingIterator
from the returnedBlockingIterable
will block onIterator.hasNext()
andBlockingIterator.next()
if no data is available. This operator may try to reduce this blocking by requesting data ahead of time.- Returns:
BlockingIterable
representingthis
Publisher
. Every timeBlockingIterable.iterator()
is invoked on theBlockingIterable
,this
Publisher
is subscribed.BlockingIterator
s returned from thisBlockingIterable
do not supportIterator.remove()
.
-
toIterable
Convertsthis
Publisher
to anBlockingIterable
. Every timeBlockingIterable.iterator()
is called on the returnedBlockingIterable
,this
Publisher
is subscribed following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.- Any items received by
PublisherSource.Subscriber.onNext(Object)
is returned from a call toBlockingIterator.next()
. - Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in aRuntimeException
if required) whenBlockingIterator.next()
. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedBlockingIterator
sIterator.hasNext()
will returnfalse
andBlockingIterator.next()
will throwNoSuchElementException
. This error will be thrown only after draining all queued data, if any.
Flow control
This operator may pre-fetch items fromthis
Publisher
if available to reduce blocking ofIterator.hasNext()
from the returnedBlockingIterable
. In order to increase responsiveness of theBlockingIterator
some amount of buffering may be done.queueCapacityHint
can be used to bound this buffer.Blocking
The returnedBlockingIterator
from the returnedBlockingIterable
will block onIterator.hasNext()
andBlockingIterator.next()
if no data is available. This operator may try to reduce this blocking by requesting data ahead of time.- Parameters:
queueCapacityHint
- Hint for the capacity of the intermediary queue that stores items that are emitted bythis
Publisher
but has not yet been returned from theBlockingIterator
.- Returns:
BlockingIterable
representingthis
Publisher
. Every timeBlockingIterable.iterator()
is invoked on theBlockingIterable
,this
Publisher
is subscribed.BlockingIterator
s returned from thisBlockingIterable
do not supportIterator.remove()
.
-
subscribeInternal
A internal subscribe method similar toPublisherSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.- Parameters:
subscriber
-PublisherSource.Subscriber
to subscribe for the result.
-
handleSubscribe
Handles a subscriber to thisPublisher
.- Parameters:
subscriber
- the subscriber.
-
from
Creates a newPublisher
that emitsvalue
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
value
- Value that the returnedPublisher
will emit.- Returns:
- A new
Publisher
that emitsvalue
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
. - See Also:
-
from
Creates a newPublisher
that emitsv1
andv2
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
v1
- The first value that the returnedPublisher
will emit.v2
- The second value that the returnedPublisher
will emit.- Returns:
- A new
Publisher
that emitsv1
andv2
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
. - See Also:
-
from
Creates a newPublisher
that emitsv1
,v2
, andv3
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
v1
- The first value that the returnedPublisher
will emit.v2
- The second value that the returnedPublisher
will emit.v3
- The third value that the returnedPublisher
will emit.- Returns:
- A new
Publisher
that emitsv1
,v2
, andv3
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
. - See Also:
-
from
Creates a newPublisher
that emits allvalues
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
values
- Values that the returnedPublisher
will emit.- Returns:
- A new
Publisher
that emits allvalues
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
. - See Also:
-
fromIterable
Create a newPublisher
that when subscribed will get anIterator
viaIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of theiterable
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
iterable
- used to obtain instances ofIterator
to extract data from.Iterable.iterator()
must not returnnull
. If this is of typeBlockingIterable
then any generatedBlockingIterator
s will have theirBlockingIterator.close()
method called if an error occurs.- Returns:
- a new
Publisher
that when subscribed will get anIterator
viaIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromBlockingIterable
public static <T> Publisher<T> fromBlockingIterable(BlockingIterable<? extends T> iterable, LongSupplier timeoutSupplier, TimeUnit unit) Create a newPublisher
that when subscribed will get aBlockingIterator
viaBlockingIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of theiterable
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
iterable
- used to obtain instances ofIterator
to extract data from.Iterable.iterator()
must not returnnull
. Any generatedBlockingIterator
s will have theirBlockingIterator.close()
method called if an error occurs.timeoutSupplier
- ALongSupplier
which provides the time duration to wait for each interaction withiterable
.unit
- The time units for thetimeout
duration.- Returns:
- a new
Publisher
that when subscribed will get aBlockingIterator
viaBlockingIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromInputStream
Deprecated.Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The resulting publisher is not replayable and supports only a single
PublisherSource.Subscriber
.After a returned
Publisher
is subscribed, it owns the passedInputStream
, meaning that theInputStream
will be automatically closed when thePublisher
is cancelled or terminated. Not necessary to close theInputStream
after subscribe, but it should be closed when control flow never subscribes to the returnedPublisher
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of thestream
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Parameters:
stream
- provides the data in the form ofbyte[]
to be emitted to thePublisherSource.Subscriber
by the returnedPublisher
. Given the blocking nature ofInputStream
, assumePublisherSource.Subscription.request(long)
can block when the underlyingInputStream
blocks onInputStream.read(byte[], int, int)
.- Returns:
- a new
Publisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromInputStream
Deprecated.Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The resulting publisher is not replayable and supports only a single
PublisherSource.Subscriber
.After a returned
Publisher
is subscribed, it owns the passedInputStream
, meaning that theInputStream
will be automatically closed when thePublisher
is cancelled or terminated. Not necessary to close theInputStream
after subscribe, but it should be closed when control flow never subscribes to the returnedPublisher
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of thestream
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Parameters:
stream
- provides the data in the form ofbyte[]
to be emitted to thePublisherSource.Subscriber
by the returnedPublisher
. Given the blocking nature ofInputStream
, assumePublisherSource.Subscription.request(long)
can block when the underlyingInputStream
blocks onInputStream.read(byte[], int, int)
.readChunkSize
- the maximum length ofbyte[]
chunks which will be read from theInputStream
and emitted by the returnedPublisher
.- Returns:
- a new
Publisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromInputStream
Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
as a mapped typeT
and thenPublisherSource.Subscriber.onComplete()
.The resulting publisher is not replayable and supports only a single
PublisherSource.Subscriber
.After a returned
Publisher
is subscribed, it owns the passedInputStream
, meaning that theInputStream
will be automatically closed when thePublisher
is cancelled or terminated. Not necessary to close theInputStream
after subscribe, but it should be closed when control flow never subscribes to the returnedPublisher
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of thestream
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.Given the blocking nature of
InputStream
, assumePublisherSource.Subscription.request(long)
can block when the underlyingInputStream
blocks onInputStream.read(byte[], int, int)
.- Type Parameters:
T
- Type of the items emitted by the returnedPublisher
.- Parameters:
stream
- provides the data in the form ofbyte[]
buffer regions for the specifiedByteArrayMapper
.mapper
- a mapper to transform rawbyte[]
buffer regions into a desired typeT
to be emitted to thePublisherSource.Subscriber
by the returnedPublisher
.- Returns:
- a new
Publisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
as a mapped typeT
and thenPublisherSource.Subscriber.onComplete()
.
-
range
-
range
Create a newPublisher
that when subscribed will emit allInteger
s within the range of [begin
,end
) with an increment ofstride
between each signal.- Parameters:
begin
- The beginning of the range (inclusive).end
- The end of the range (exclusive).stride
- The amount to increment in between each signal.- Returns:
- a new
Publisher
that when subscribed will emit allInteger
s within the range of [begin
,end
) with an increment ofstride
between each signal. - See Also:
-
empty
Creates a newPublisher
that completes when subscribed without emitting any item to itsPublisherSource.Subscriber
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Returns:
- A new
Publisher
that completes when subscribed without emitting any item to itsPublisherSource.Subscriber
. - See Also:
-
never
Creates a newPublisher
that never emits any item to itsPublisherSource.Subscriber
and never call any terminal methods on it.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Returns:
- A new
Publisher
that never emits any item to itsPublisherSource.Subscriber
and never call any terminal methods on it. - See Also:
-
failed
Creates a newPublisher
that terminates itsPublisherSource.Subscriber
with an error without emitting any item to it.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
cause
- TheThrowable
that is used to terminate thePublisherSource.Subscriber
.- Returns:
- A new
Publisher
that terminates itsPublisherSource.Subscriber
with an error without emitting any item to it. - See Also:
-
defer
Defers creation of aPublisher
till it is subscribed.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
publisherSupplier
-Supplier
to create a newPublisher
every time the returnedPublisher
is subscribed.- Returns:
- A new
Publisher
that creates a newPublisher
usingpublisherSupplier
every time it is subscribed and forwards all items and terminal events from the newly createdPublisher
to itsPublisherSource.Subscriber
. - See Also:
-
mergeAll
Merge allPublisher
s together. There is no guaranteed ordering of events emitted from the returnedPublisher
.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. } return mergedResults;
-
mergeAll
@SafeVarargs public static <T> Publisher<T> mergeAll(int maxConcurrency, Publisher<? extends T>... publishers) Merge allPublisher
s together. There is no guaranteed ordering of events emitted from the returnedPublisher
.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. } return mergedResults;
- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
maxConcurrency
- The maximum amount ofPublisher
s frompublishers
to subscribe to concurrently.publishers
- ThePublisher
s to merge together.- Returns:
- A
Publisher
which is the result of thisPublisher
andother
merged together. - See Also:
-
mergeAllDelayError
@SafeVarargs public static <T> Publisher<T> mergeAllDelayError(Publisher<? extends T>... publishers) Merge allPublisher
s together. There is no guaranteed ordering of events emitted from the returnedPublisher
. If anyPublisher
terminates in an error, the error propagation will be delayed until all terminate.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); return mergedResults;
-
mergeAllDelayError
@SafeVarargs public static <T> Publisher<T> mergeAllDelayError(int maxConcurrency, Publisher<? extends T>... publishers) Merge allPublisher
s together. There is no guaranteed ordering of events emitted from the returnedPublisher
. If anyPublisher
terminates in an error, the error propagation will be delayed until all terminate.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); return mergedResults;
- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
maxConcurrency
- The maximum amount ofPublisher
s frompublishers
to subscribe to concurrently.publishers
- ThePublisher
s to merge together.- Returns:
- A
Publisher
which is the result of thisPublisher
andother
merged together. - See Also:
-
fromInputStream(InputStream, ByteArrayMapper)
withByteArrayMapper.toByteArray()
.