T - Type of items emitted.public abstract class Publisher<T>
extends Object
PublisherSource.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.| Modifier | Constructor and Description |
|---|---|
protected |
Publisher()
New instance.
|
| Modifier and Type | Method and Description |
|---|---|
Publisher<T> |
afterCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument after Cancellable.cancel() is
called for PublisherSource.Subscriptions of the returned Publisher. |
Publisher<T> |
afterFinally(Runnable doFinally)
Invokes the
afterFinally Runnable argument after any of the following terminal
methods are called:
PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
afterFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method on
afterFinally TerminalSignalConsumer argument
after any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete() - invokes TerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable) - invokes TerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()
for PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
afterOnComplete(Runnable onComplete)
Invokes the
onComplete Runnable argument after PublisherSource.Subscriber.onComplete()
is called for PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
afterOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument after
PublisherSource.Subscriber.onError(Throwable) is called for PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
afterOnNext(Consumer<? super T> onNext)
Invokes the
onNext Consumer argument after PublisherSource.Subscriber.onNext(Object) is
called for PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
afterOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes the
onSubscribe Consumer argument after
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher. |
Publisher<T> |
afterRequest(LongConsumer onRequest)
Invokes the
onRequest LongConsumer argument after
PublisherSource.Subscription.request(long) is called for PublisherSource.Subscriptions of the returned Publisher. |
Publisher<T> |
afterSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a new
PublisherSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes all the PublisherSource.Subscriber methods after the PublisherSource.Subscribers of the returned
Publisher. |
Publisher<T> |
afterSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a new
PublisherSource.Subscription (via the subscriptionSupplier argument) for each new subscribe and
invokes all the PublisherSource.Subscription methods after the PublisherSource.Subscriptions of the returned
Publisher. |
Publisher<T> |
beforeCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument before Cancellable.cancel() is
called for PublisherSource.Subscriptions of the returned Publisher. |
Publisher<T> |
beforeFinally(Runnable doFinally)
Invokes the
beforeFinally Runnable argument before any of the following terminal
methods are called:
PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
beforeFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method on
beforeFinally TerminalSignalConsumer argument
before any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete() - invokes TerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable) - invokes TerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()
for PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
beforeOnComplete(Runnable onComplete)
Invokes the
onComplete Runnable argument before PublisherSource.Subscriber.onComplete()
is called for PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
beforeOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument before
PublisherSource.Subscriber.onError(Throwable) is called for PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
beforeOnNext(Consumer<? super T> onNext)
Invokes the
onNext Consumer argument before PublisherSource.Subscriber.onNext(Object) is
called for PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
beforeOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes the
onSubscribe Consumer argument before
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher. |
Publisher<T> |
beforeRequest(LongConsumer onRequest)
Invokes the
onRequest LongConsumer argument before
PublisherSource.Subscription.request(long) is called for PublisherSource.Subscriptions of the returned Publisher. |
Publisher<T> |
beforeSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a new
PublisherSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and
invokes all the PublisherSource.Subscriber methods before the PublisherSource.Subscribers of the returned
Publisher. |
Publisher<T> |
beforeSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a new
PublisherSource.Subscription (via the subscriptionSupplier argument) on each call to
subscribe and invokes all the PublisherSource.Subscription methods before the PublisherSource.Subscriptions of
the returned Publisher. |
<BC extends BufferStrategy.Accumulator<T,B>,B> |
buffer(BufferStrategy<T,BC,B> strategy)
|
<R> Single<R> |
collect(Supplier<? extends R> resultFactory,
BiFunction<? super R,? super T,R> collector)
Collects all items emitted by this
Publisher into a single item. |
Completable |
completableOrError()
Converts this
Publisher to a Completable. |
Publisher<T> |
concat(Completable next)
|
Publisher<T> |
concat(Publisher<? extends T> next)
|
Publisher<T> |
concat(Single<? extends T> next)
|
static <T> Publisher<T> |
defer(Supplier<? extends Publisher<? extends T>> publisherSupplier)
Defers creation of a
Publisher till it is subscribed. |
static <T> Publisher<T> |
empty()
Creates a new
Publisher that completes when subscribed without emitting any item to its
PublisherSource.Subscriber. |
static <T> Publisher<T> |
failed(Throwable cause)
Creates a new
Publisher that terminates its PublisherSource.Subscriber with an error without emitting any item to
it. |
Publisher<T> |
filter(Predicate<? super T> predicate)
Filters items emitted by this
Publisher. |
Single<T> |
firstOrElse(Supplier<T> defaultValueSupplier)
|
Single<T> |
firstOrError()
Ensures that this
Publisher emits exactly a single PublisherSource.Subscriber.onNext(Object) to its
PublisherSource.Subscriber. |
Completable |
flatMapCompletable(Function<? super T,? extends Completable> mapper)
Map each element of this
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure. |
Completable |
flatMapCompletable(Function<? super T,? extends Completable> mapper,
int maxConcurrency)
Map each element of this
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure. |
Completable |
flatMapCompletableDelayError(Function<? super T,? extends Completable> mapper)
Map each element of this
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure. |
Completable |
flatMapCompletableDelayError(Function<? super T,? extends Completable> mapper,
int maxConcurrency)
Map each element of this
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure. |
Completable |
flatMapCompletableDelayError(Function<? super T,? extends Completable> mapper,
int maxConcurrency,
int maxDelayedErrorsHint)
Map each element of this
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure. |
<R> Publisher<R> |
flatMapConcatIterable(Function<? super T,? extends Iterable<? extends R>> mapper)
|
<R> Publisher<R> |
flatMapMerge(Function<? super T,? extends Publisher<? extends R>> mapper)
|
<R> Publisher<R> |
flatMapMerge(Function<? super T,? extends Publisher<? extends R>> mapper,
int maxConcurrency)
|
<R> Publisher<R> |
flatMapMergeDelayError(Function<? super T,? extends Publisher<? extends R>> mapper)
|
<R> Publisher<R> |
flatMapMergeDelayError(Function<? super T,? extends Publisher<? extends R>> mapper,
int maxConcurrency)
|
<R> Publisher<R> |
flatMapMergeDelayError(Function<? super T,? extends Publisher<? extends R>> mapper,
int maxConcurrency,
int maxDelayedErrorsHint)
|
<R> Publisher<R> |
flatMapMergeSingle(Function<? super T,? extends Single<? extends R>> mapper)
|
<R> Publisher<R> |
flatMapMergeSingle(Function<? super T,? extends Single<? extends R>> mapper,
int maxConcurrency)
|
<R> Publisher<R> |
flatMapMergeSingleDelayError(Function<? super T,? extends Single<? extends R>> mapper)
|
<R> Publisher<R> |
flatMapMergeSingleDelayError(Function<? super T,? extends Single<? extends R>> mapper,
int maxConcurrency)
|
<R> Publisher<R> |
flatMapMergeSingleDelayError(Function<? super T,? extends Single<? extends R>> mapper,
int maxConcurrency,
int maxDelayedErrorsHint)
|
Cancellable |
forEach(Consumer<? super T> forEach)
|
static <T> Publisher<T> |
from(T... values)
Creates a new
Publisher that emits all values to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete(). |
static <T> Publisher<T> |
from(T value)
Creates a new
Publisher that emits value to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete(). |
static <T> Publisher<T> |
from(T v1,
T v2)
Creates a new
Publisher that emits v1 and v2 to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete(). |
static <T> Publisher<T> |
from(T v1,
T v2,
T v3)
Creates a new
Publisher that emits v1, v2, and v3 to its PublisherSource.Subscriber and
then PublisherSource.Subscriber.onComplete(). |
static <T> Publisher<T> |
fromBlockingIterable(BlockingIterable<? extends T> iterable,
LongSupplier timeoutSupplier,
TimeUnit unit)
Create a new
Publisher that when subscribed will get a BlockingIterator via
BlockingIterable.iterator() and emit all values to the PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete(). |
static Publisher<byte[]> |
fromInputStream(InputStream stream)
Create a new
Publisher that when subscribed will emit all data from the InputStream to the
PublisherSource.Subscriber and then PublisherSource.Subscriber.onComplete(). |
static Publisher<byte[]> |
fromInputStream(InputStream stream,
int readChunkSize)
Create a new
Publisher that when subscribed will emit all data from the InputStream to the
PublisherSource.Subscriber and then PublisherSource.Subscriber.onComplete(). |
static <T> Publisher<T> |
fromIterable(Iterable<? extends T> iterable)
Create a new
Publisher that when subscribed will get an Iterator via Iterable.iterator()
and emit all values to the PublisherSource.Subscriber and then PublisherSource.Subscriber.onComplete(). |
<Key> Publisher<GroupedPublisher<Key,T>> |
groupBy(Function<? super T,? extends Key> keySelector,
int groupMaxQueueSize)
Splits items from this
Publisher into dynamically generated GroupedPublishers. |
<Key> Publisher<GroupedPublisher<Key,T>> |
groupBy(Function<? super T,? extends Key> keySelector,
int groupMaxQueueSize,
int expectedGroupCountHint)
Splits items from this
Publisher into dynamically generated GroupedPublishers. |
<Key> Publisher<GroupedPublisher<Key,T>> |
groupToMany(Function<? super T,? extends Iterator<? extends Key>> keySelector,
int groupMaxQueueSize)
The semantics are identical to
groupBy(Function, int) except that the keySelector can map each
data to multiple keys. |
<Key> Publisher<GroupedPublisher<Key,T>> |
groupToMany(Function<? super T,? extends Iterator<? extends Key>> keySelector,
int groupMaxQueueSize,
int expectedGroupCountHint)
The semantics are identical to
groupBy(Function, int) except that the keySelector can map each
data to multiple keys. |
protected abstract void |
handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Handles a subscriber to this
Publisher. |
Publisher<T> |
idleTimeout(Duration duration)
Deprecated.
|
Publisher<T> |
idleTimeout(Duration duration,
Executor timeoutExecutor)
Deprecated.
|
Publisher<T> |
idleTimeout(long duration,
TimeUnit unit)
Deprecated.
|
Publisher<T> |
idleTimeout(long duration,
TimeUnit unit,
Executor timeoutExecutor)
Deprecated.
|
Completable |
ignoreElements()
Ignores all elements emitted by this
Publisher and forwards the termination signal to the returned
Completable. |
<R> Publisher<R> |
liftAsync(PublisherOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators.
|
<R> Publisher<R> |
liftSync(PublisherOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators.
|
<R> Single<R> |
liftSyncToSingle(PublisherToSingleOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators.
|
<R> Publisher<R> |
map(Function<? super T,? extends R> mapper)
Transforms elements emitted by this
Publisher into a different type. |
Publisher<T> |
multicastToExactly(int expectedSubscribers)
Create a
Publisher that multicasts all the signals to exactly expectedSubscribers. |
Publisher<T> |
multicastToExactly(int expectedSubscribers,
int maxQueueSize)
Create a
Publisher that allows exactly expectedSubscribers subscribes. |
static <T> Publisher<T> |
never()
Creates a new
Publisher that never emits any item to its PublisherSource.Subscriber and never call any terminal
methods on it. |
Publisher<T> |
onErrorComplete()
Transform errors emitted on this
Publisher into a PublisherSource.Subscriber.onComplete() signal
(e.g. |
<E extends Throwable> |
onErrorComplete(Class<E> type)
Transform errors emitted on this
Publisher which match type into a
PublisherSource.Subscriber.onComplete() signal (e.g. |
Publisher<T> |
onErrorComplete(Predicate<? super Throwable> predicate)
Transform errors emitted on this
Publisher which match predicate into a
PublisherSource.Subscriber.onComplete() signal (e.g. |
<E extends Throwable> |
onErrorMap(Class<E> type,
Function<? super E,? extends Throwable> mapper)
Transform errors emitted on this
Publisher which match type into a different error. |
Publisher<T> |
onErrorMap(Function<? super Throwable,? extends Throwable> mapper)
Transform errors emitted on this
Publisher into a different error. |
Publisher<T> |
onErrorMap(Predicate<? super Throwable> predicate,
Function<? super Throwable,? extends Throwable> mapper)
Transform errors emitted on this
Publisher which match predicate into a different error. |
<E extends Throwable> |
onErrorResume(Class<E> type,
Function<? super E,? extends Publisher<? extends T>> nextFactory)
|
Publisher<T> |
onErrorResume(Function<? super Throwable,? extends Publisher<? extends T>> nextFactory)
|
Publisher<T> |
onErrorResume(Predicate<? super Throwable> predicate,
Function<? super Throwable,? extends Publisher<? extends T>> nextFactory)
|
<E extends Throwable> |
onErrorReturn(Class<E> type,
Function<? super E,? extends T> itemSupplier)
Transform errors emitted on this
Publisher which match type into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.Subscriber.onComplete() signals (e.g. |
Publisher<T> |
onErrorReturn(Function<? super Throwable,? extends T> itemSupplier)
Transform errors emitted on this
Publisher into PublisherSource.Subscriber.onNext(Object) then
PublisherSource.Subscriber.onComplete() signals (e.g. |
Publisher<T> |
onErrorReturn(Predicate<? super Throwable> predicate,
Function<? super Throwable,? extends T> itemSupplier)
Transform errors emitted on this
Publisher which match predicate into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.Subscriber.onComplete() signals (e.g. |
Publisher<T> |
publishAndSubscribeOn(Executor executor)
Deprecated.
This operator has been deprecated because of upcoming behavior changes in how offloading via
operators is done. Originally offloading for subscribe/subscription was applied at the "bottom" of chain
(logically the last operator in the chain closest to the subscriber), and offloading for subscriber was applied
at the "top" of the operator chain (logically the first operator in the chain after the async source). The
current offloading doesn't respect the order in which the operators are applied, the offloading is the same
regardless of where the operators are placed in the chain. However, this behavior will soon change to instead
respect operator placement order and apply offloading exactly where the offloading operators are applied in the
chain. This change in behavior means that it no longer makes sense to fuse the offloading of publish and
subscribe as the location of the operators in the chain will now be significant. Publish and subscribe
offloading, when required, will typically be placed in different locations. Use separate, appropriately placed,
subscribeOn(Executor) and publishOn(Executor) operators instead. |
Publisher<T> |
publishAndSubscribeOnOverride(Executor executor)
Deprecated.
This method will be removed in a future release. Consider switching to
publishAndSubscribeOn(Executor) and/or using Executor.execute(Runnable) for offloading. |
Publisher<T> |
publishOn(Executor executor)
|
Publisher<T> |
publishOnOverride(Executor executor)
Deprecated.
This method will be removed in a future release. Consider switching to
publishOn(Executor)
and/or using Executor.execute(Runnable) for offloading. |
static Publisher<Integer> |
range(int begin,
int end)
Create a new
Publisher that when subscribed will emit all Integers within the range of
[begin, end). |
static Publisher<Integer> |
range(int begin,
int end,
int stride)
Create a new
Publisher that when subscribed will emit all Integers within the range of
[begin, end) with an increment of stride between each signal. |
Publisher<T> |
recoverWith(Function<Throwable,? extends Publisher<? extends T>> nextFactory)
Deprecated.
|
Publisher<T> |
repeat(IntPredicate shouldRepeat)
|
Publisher<T> |
repeatWhen(IntFunction<? extends Completable> repeatWhen)
Re-subscribes to this
Publisher when it completes and the Completable returned by the supplied
IntFunction completes successfully. |
Publisher<T> |
retry(BiIntPredicate<Throwable> shouldRetry)
|
Publisher<T> |
retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
Re-subscribes to this
Publisher if an error is emitted and the Completable returned by the
supplied BiIntFunction completes successfully. |
<R> Publisher<R> |
scanWith(Supplier<? extends ScanWithMapper<? super T,? extends R>> mapperSupplier)
Apply a function to each
PublisherSource.Subscriber.onNext(Object) emitted by this Publisher as well as
optionally concat one PublisherSource.Subscriber.onNext(Object) signal before the terminal signal is emitted downstream. |
<R> Publisher<R> |
scanWith(Supplier<R> initial,
BiFunction<R,? super T,R> accumulator)
Apply a
BiFunction to each PublisherSource.Subscriber.onNext(Object) emitted by this Publisher and an
accumulated state. |
<R> Publisher<R> |
scanWithLifetime(Supplier<? extends ScanWithLifetimeMapper<? super T,? extends R>> mapperSupplier)
Apply a function to each
PublisherSource.Subscriber.onNext(Object) emitted by this Publisher as well as
optionally concat one PublisherSource.Subscriber.onNext(Object) signal before the terminal signal is emitted downstream. |
protected void |
subscribeInternal(PublisherSource.Subscriber<? super T> subscriber)
A internal subscribe method similar to
PublisherSource.subscribe(Subscriber) which can be used by
different implementations to subscribe. |
Publisher<T> |
subscribeOn(Executor executor)
Creates a new
Publisher that will use the passed Executor to invoke the following methods:
All PublisherSource.Subscription methods.
The handleSubscribe(PublisherSource.Subscriber) method.
This method does not override preceding Executors, if any, specified for this
Publisher. |
Publisher<T> |
subscribeOnOverride(Executor executor)
Deprecated.
This method will be removed in a future release. Consider switching to
subscribeOn(Executor)
and/or using Executor.execute(Runnable) for offloading. |
Publisher<T> |
subscribeShareContext()
Signifies that when the returned
Publisher is subscribed to, the AsyncContext will be shared
instead of making a copy. |
Publisher<T> |
takeAtMost(long numElements)
|
Publisher<T> |
takeUntil(Completable until)
Takes elements until
Completable is terminated successfully or with failure. |
Publisher<T> |
takeWhile(Predicate<? super T> predicate)
Takes elements while
Predicate is true and then cancel PublisherSource.Subscription of this
Publisher once it returns false. |
Publisher<T> |
timeout(Duration duration)
|
Publisher<T> |
timeout(Duration duration,
Executor timeoutExecutor)
|
Publisher<T> |
timeout(long duration,
TimeUnit unit)
|
Publisher<T> |
timeout(long duration,
TimeUnit unit,
Executor timeoutExecutor)
|
Publisher<T> |
timeoutTerminal(Duration duration)
|
Publisher<T> |
timeoutTerminal(Duration duration,
Executor timeoutExecutor)
|
Publisher<T> |
timeoutTerminal(long duration,
TimeUnit unit)
|
Publisher<T> |
timeoutTerminal(long duration,
TimeUnit unit,
Executor timeoutExecutor)
|
CompletionStage<Collection<T>> |
toCompletionStage()
|
<R> CompletionStage<R> |
toCompletionStage(Supplier<? extends R> resultFactory,
BiFunction<? super R,? super T,R> reducer)
|
Future<Collection<T>> |
toFuture()
|
<R> Future<R> |
toFuture(Supplier<? extends R> resultFactory,
BiFunction<? super R,? super T,R> reducer)
|
InputStream |
toInputStream(Function<? super T,byte[]> serializer)
Subscribes to
this Publisher and converts all signals received by the PublisherSource.Subscriber to the
returned InputStream following the below rules:
PublisherSource.Subscription received by PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is used to
request more data when required. |
InputStream |
toInputStream(Function<? super T,byte[]> serializer,
int queueCapacity)
Subscribes to
this Publisher and converts all signals received by the PublisherSource.Subscriber to the
returned InputStream following the below rules:
PublisherSource.Subscription received by PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is used to
request more data when required. |
BlockingIterable<T> |
toIterable()
|
BlockingIterable<T> |
toIterable(int queueCapacityHint)
|
Publisher<T> |
whenCancel(Runnable onCancel)
Invokes the
onCancel Runnable argument when Cancellable.cancel() is called for
Subscriptions of the returned Publisher. |
Publisher<T> |
whenFinally(Runnable doFinally)
Invokes the
whenFinally Runnable argument exactly once, when any of the following terminal
methods are called:
PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
for PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
whenFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method on
whenFinally TerminalSignalConsumer argument when any of the
following terminal methods are called:
PublisherSource.Subscriber.onComplete() - invokes TerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable) - invokes TerminalSignalConsumer.onError(Throwable)
Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()
for PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
whenOnComplete(Runnable onComplete)
Invokes the
onComplete Runnable argument when PublisherSource.Subscriber.onComplete() is called for
PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
whenOnError(Consumer<Throwable> onError)
Invokes the
onError Consumer argument when PublisherSource.Subscriber.onError(Throwable) is called for
PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
whenOnNext(Consumer<? super T> onNext)
Invokes the
onNext Consumer argument when PublisherSource.Subscriber.onNext(Object) is called for
PublisherSource.Subscribers of the returned Publisher. |
Publisher<T> |
whenOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes the
onSubscribe Consumer argument when
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher. |
Publisher<T> |
whenRequest(LongConsumer onRequest)
Invokes the
onRequest LongConsumer argument when PublisherSource.Subscription.request(long) is called for
PublisherSource.Subscriptions of the returned Publisher. |
Publisher<T> |
whenSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a new
PublisherSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes methods on that PublisherSource.Subscriber when the corresponding methods are called for PublisherSource.Subscribers of
the returned Publisher. |
Publisher<T> |
whenSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a new
PublisherSource.Subscription (via the subscriptionSupplier argument) for each new subscribe and
invokes all the PublisherSource.Subscription methods when the corresponding methods are called for PublisherSource.Subscriptions
of the returned Publisher. |
public final <R> Publisher<R> map(Function<? super T,? extends R> mapper)
Publisher 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;
R - Type of the items emitted by the returned Publisher.mapper - Function to transform each item emitted by this Publisher.Publisher that transforms elements emitted by this Publisher into a different type.public final Publisher<T> filter(Predicate<? super T> predicate)
Publisher.
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;
predicate - for the filter.Publisher that only emits the items that pass the predicate.public final <R> Publisher<R> scanWith(Supplier<R> initial, BiFunction<R,? super T,R> accumulator)
BiFunction to each PublisherSource.Subscriber.onNext(Object) emitted by this Publisher 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;
R - Type of the items emitted by the returned Publisher.initial - Invoked on each PublisherSource.subscribe(Subscriber) and provides the initial state for
each PublisherSource.Subscriber.accumulator - Used to accumulate the current state in combination with each
PublisherSource.Subscriber.onNext(Object) from this Publisher.Publisher that transforms elements emitted by this Publisher into a different type.public final <R> Publisher<R> scanWith(Supplier<? extends ScanWithMapper<? super T,? extends R>> mapperSupplier)
PublisherSource.Subscriber.onNext(Object) emitted by this Publisher as well as
optionally concat one PublisherSource.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;
R - Type of the items emitted by the returned Publisher.mapperSupplier - Invoked on each PublisherSource.subscribe(Subscriber) and maintains any necessary
state for the mapping/accumulation for each PublisherSource.Subscriber.Publisher that transforms elements emitted by this Publisher into a different type.public final <R> Publisher<R> scanWithLifetime(Supplier<? extends ScanWithLifetimeMapper<? super T,? extends R>> mapperSupplier)
PublisherSource.Subscriber.onNext(Object) emitted by this Publisher as well as
optionally concat one PublisherSource.Subscriber.onNext(Object) signal before the terminal signal is emitted downstream.
Additionally the ScanWithLifetimeMapper.afterFinally() method will be invoked on terminal or cancel
signals which enables cleanup of state (if required). This provides a similar lifetime management as
TerminalSignalConsumer.
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;
R - Type of the items emitted by the returned Publisher.mapperSupplier - Invoked on each PublisherSource.subscribe(Subscriber) and maintains any necessary
state for the mapping/accumulation for each PublisherSource.Subscriber.Publisher that transforms elements emitted by this Publisher into a different type.public final Publisher<T> onErrorComplete()
Publisher into a PublisherSource.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;
Publisher which transform errors emitted on this Publisher into a
PublisherSource.Subscriber.onComplete() signal (e.g. swallows the error).public final <E extends Throwable> Publisher<T> onErrorComplete(Class<E> type)
Publisher which match type into a
PublisherSource.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;
E - The Throwable type.type - The Throwable type to filter, operator will not apply for errors which don't match this type.Publisher which transform errors emitted on this Publisher which match type
into a PublisherSource.Subscriber.onComplete() signal (e.g. swallows the error).public final Publisher<T> onErrorComplete(Predicate<? super Throwable> predicate)
Publisher which match predicate into a
PublisherSource.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;
predicate - returns true if the Throwable should be transformed to and
PublisherSource.Subscriber.onComplete() signal. Returns false to propagate the error.Publisher which transform errors emitted on this Publisher which match
predicate into a PublisherSource.Subscriber.onComplete() signal (e.g. swallows the error).public final Publisher<T> onErrorReturn(Function<? super Throwable,? extends T> itemSupplier)
Publisher into PublisherSource.Subscriber.onNext(Object) then
PublisherSource.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;
itemSupplier - returns the element to emit to PublisherSource.Subscriber.onNext(Object).Publisher which transform errors emitted on this Publisher into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.Subscriber.onComplete() signals (e.g. swallows the error).public final <E extends Throwable> Publisher<T> onErrorReturn(Class<E> type, Function<? super E,? extends T> itemSupplier)
Publisher which match type into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.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;
E - The type of Throwable to transform.type - The Throwable type to filter, operator will not apply for errors which don't match this type.itemSupplier - returns the element to emit to PublisherSource.Subscriber.onNext(Object).Publisher which transform errors emitted on this Publisher into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.Subscriber.onComplete() signals (e.g. swallows the error).public final Publisher<T> onErrorReturn(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends T> itemSupplier)
Publisher which match predicate into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.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;
predicate - returns true if the Throwable should be transformed to
PublisherSource.Subscriber.onNext(Object) then PublisherSource.Subscriber.onComplete() signals. Returns false to
propagate the error.itemSupplier - returns the element to emit to PublisherSource.Subscriber.onNext(Object).Publisher which transform errors emitted on this Publisher into
PublisherSource.Subscriber.onNext(Object) then PublisherSource.Subscriber.onComplete() signals (e.g. swallows the error).public final Publisher<T> onErrorMap(Function<? super Throwable,? extends Throwable> mapper)
Publisher 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;
mapper - returns the error used to terminate the returned Publisher.Publisher which transform errors emitted on this Publisher into a different error.public final <E extends Throwable> Publisher<T> onErrorMap(Class<E> type, Function<? super E,? extends Throwable> mapper)
Publisher which match type 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;
E - The type of Throwable to transform.type - The Throwable type to filter, operator will not apply for errors which don't match this type.mapper - returns the error used to terminate the returned Publisher.Publisher which transform errors emitted on this Publisher into a different error.public final Publisher<T> onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends Throwable> mapper)
Publisher which match predicate 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;
predicate - returns true if the Throwable should be transformed via mapper. Returns
false to propagate the original error.mapper - returns the error used to terminate the returned Publisher.Publisher which transform errors emitted on this Publisher into a different error.public final Publisher<T> onErrorResume(Function<? super Throwable,? extends Publisher<? extends T>> nextFactory)
Publisher by using another Publisher provided by the
passed nextFactory.
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;
public final <E extends Throwable> Publisher<T> onErrorResume(Class<E> type, Function<? super E,? extends Publisher<? extends T>> nextFactory)
Publisher which match type by using another Publisher
provided by the passed nextFactory.
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;
E - The type of Throwable to transform.type - The Throwable type to filter, operator will not apply for errors which don't match this type.nextFactory - Returns the next Publisher, when this Publisher emits an error.Publisher that recovers from an error from this Publisher by using another
Publisher provided by the passed nextFactory.public final Publisher<T> onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable,? extends Publisher<? extends T>> nextFactory)
Publisher which match predicate by using another
Publisher provided by the passed nextFactory.
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;
predicate - returns true if the Throwable should be transformed via nextFactory.
Returns false to propagate the original error.nextFactory - Returns the next Publisher, when this Publisher emits an error.Publisher that recovers from an error from this Publisher by using another
Publisher provided by the passed nextFactory.@Deprecated public final Publisher<T> recoverWith(Function<Throwable,? extends Publisher<? extends T>> nextFactory)
onErrorResume(Function).Publisher by using another Publisher provided by the
passed nextFactory.
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;
nextFactory - Returns the next Publisher, when this Publisher emits an error.Publisher that recovers from an error from this Publisher by using another
Publisher provided by the passed nextFactory.public final <R> Publisher<R> flatMapMerge(Function<? super T,? extends Publisher<? extends R>> mapper)
Publisher into a Publisher<R> and flatten all signals
emitted from each mapped Publisher<R> into the returned
Publisher<R>.
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;
public final <R> Publisher<R> flatMapMerge(Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency)
Publisher into a Publisher<R> and flatten all signals
emitted from each mapped Publisher<R> into the returned
Publisher<R>.
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;
R - The type of mapped Publisher.mapper - Convert each item emitted by this Publisher into another Publisher.maxConcurrency - Maximum amount of outstanding upstream demand.Publisher which flattens the emissions from all mapped Publishers.public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T,? extends Publisher<? extends R>> mapper)
Publisher into a Publisher<R> and flatten all signals
emitted from each mapped Publisher<R> into the returned
Publisher<R>.
This is the same as flatMapMerge(Function) just that if any mapped Publisher returned by
mapper, terminates with an error, the returned Publisher will not immediately terminate. Instead,
it will wait for this Publisher and all mapped Publishers to terminate and then terminate the
returned Publisher with all errors emitted by the mapped Publishers.
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);
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency)
Publisher into a Publisher<R> and flatten all signals
emitted from each mapped Publisher<R> into the returned
Publisher<R>.
This is the same as flatMapMerge(Function) just that if any mapped Publisher returned by
mapper, terminates with an error, the returned Publisher will not immediately terminate. Instead,
it will wait for this Publisher and all mapped Publishers to terminate and then terminate the
returned Publisher with all errors emitted by the mapped Publishers.
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);
R - The type of mapped Publisher.mapper - Convert each item emitted by this Publisher into another Publisher.maxConcurrency - Maximum amount of outstanding upstream demand.Publisher which flattens the emissions from all mapped Publishers.public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Publisher into a Publisher<R> and flatten all signals
emitted from each mapped Publisher<R> into the returned
Publisher<R>.
This is the same as flatMapMerge(Function) just that if any mapped Publisher returned by
mapper, terminates with an error, the returned Publisher will not immediately terminate. Instead,
it will wait for this Publisher and all mapped Publishers to terminate and then terminate the
returned Publisher with all errors emitted by the mapped Publishers.
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);
R - The type of mapped Publisher.mapper - Convert each item emitted by this Publisher into another Publisher.maxConcurrency - Maximum amount of outstanding upstream demand.maxDelayedErrorsHint - The maximum amount of errors that will be queued. After this point exceptions maybe
discarded to reduce memory consumption.Publisher which flattens the emissions from all mapped Publishers.public final <R> Publisher<R> flatMapMergeSingle(Function<? super T,? extends Single<? extends R>> mapper)
Publisher into a Single<R> and flatten all signals
emitted from each mapped Single<R> into the returned
Publisher<R>.
To control the amount of concurrent processing done by this operator see
flatMapMergeSingle(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(() -> {
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;
R - Type of items emitted by the returned Publisher.mapper - Function to convert each item emitted by this Publisher into a Single.Publisher that emits all items emitted by each single produced by mapper.flatMapMergeSingle(Function, int)public final <R> Publisher<R> flatMapMergeSingle(Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency)
Publisher into a Single<R> and flatten all signals
emitted from each mapped Single<R> into the returned
Publisher<R>.
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(() -> {
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;
R - Type of items emitted by the returned Publisher.mapper - Function to convert each item emitted by this Publisher into a Single.maxConcurrency - Maximum active Singles at any time.
Even if the number of items requested by a PublisherSource.Subscriber is more than this number, this will never request
more than this number at any point.Publisher that emits all items emitted by each single produced by mapper.public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T,? extends Single<? extends R>> mapper)
Publisher into a Single<R> and flatten all signals
emitted from each mapped Single<R> into the returned
Publisher<R>.
The behavior is the same as flatMapMergeSingle(Function, int) with the exception that if any
Single returned by mapper, terminates with an error, the returned Publisher will not
immediately terminate. Instead, it will wait for this Publisher and all Singles to terminate and
then terminate the returned Publisher with all errors emitted by the Singles produced by the
mapper.
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, 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 : tResults) {
// Note that flatMap process results in parallel.
e.execute(() -> {
try {
R r = mapper.apply(t); // Asynchronous result is flatten into a value by this operator.
rResults.add(r);
} 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);
R - Type of items emitted by the returned Publisher.mapper - Function to convert each item emitted by this Publisher into a Single.Publisher that emits all items emitted by each single produced by mapper.flatMapMergeSingleDelayError(Function, int)public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency)
Publisher into a Single<R> and flatten all signals
emitted from each mapped Single<R> into the returned
Publisher<R>.
The behavior is the same as flatMapMergeSingle(Function, int) with the exception that if any
Single returned by mapper, terminates with an error, the returned Publisher will not
immediately terminate. Instead, it will wait for this Publisher and all Singles to terminate and
then terminate the returned Publisher with all errors emitted by the Singles produced by the
mapper.
This method is similar to map(Function) but the result is asynchronous, 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 : tResults) {
// Note that flatMap process results in parallel.
e.execute(() -> {
try {
R r = mapper.apply(t); // Asynchronous result is flatten into a value by this operator.
rResults.add(r);
} 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);
R - Type of items emitted by the returned Publisher.mapper - Function to convert each item emitted by this Publisher into a Single.maxConcurrency - Maximum active Singles at any time.
Even if the number of items requested by a PublisherSource.Subscriber is more than this number,
this will never request more than this number at any point.Publisher that emits all items emitted by each single produced by mapper.public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Publisher into a Single<R> and flatten all signals
emitted from each mapped Single<R> into the returned
Publisher<R>.
The behavior is the same as flatMapMergeSingle(Function, int) with the exception that if any
Single returned by mapper, terminates with an error, the returned Publisher will not
immediately terminate. Instead, it will wait for this Publisher and all Singles to terminate and
then terminate the returned Publisher with all errors emitted by the Singles produced by the
mapper.
This method is similar to map(Function) but the result is asynchronous, 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 : tResults) {
// Note that flatMap process results in parallel.
e.execute(() -> {
try {
R r = mapper.apply(t); // Asynchronous result is flatten into a value by this operator.
rResults.add(r);
} 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);
R - Type of items emitted by the returned Publisher.mapper - Function to convert each item emitted by this Publisher into a Single.maxConcurrency - Maximum active Singles at any time.
Even if the number of items requested by a PublisherSource.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.Publisher that emits all items emitted by each single produced by mapper.public final Completable flatMapCompletable(Function<? super T,? extends Completable> mapper)
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure.
If the returned Completable should wait for the termination of all mapped Completables 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.
}
mapper - Function to convert each item emitted by this Publisher into a Completable.Completable that terminates successfully if all the intermediate Completables have
terminated successfully or any one of them has terminated with a failure.flatMapCompletable(Function, int),
flatMapCompletableDelayError(Function)public final Completable flatMapCompletable(Function<? super T,? extends Completable> mapper, int maxConcurrency)
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure.
If the returned Completable should wait for the termination of all mapped Completables 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.
}
mapper - Function to convert each item emitted by this Publisher into a Completable.maxConcurrency - Maximum active Completables at any time.Completable that terminates successfully if all the intermediate Completables have
terminated successfully or any one of them has terminated with a failure.flatMapCompletable(Function),
flatMapCompletableDelayError(Function, int)public final Completable flatMapCompletableDelayError(Function<? super T,? extends Completable> mapper)
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure.
If any mapped Completable terminates with an error the returned Completable will not immediately
terminate. Instead, it will wait for this Publisher and all mapped Completables 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:
Executor e = ...;
List<Throwable> errors = ...; // assume this is thread safe
CountDownLatch latch = new CountDownLatch(tResults.size());
for (T t : tResults) {
// Note that flatMap process results in parallel.
e.execute(() -> {
try {
mapper.apply(t); // Asynchronous result is flattened by this operator.
} catch (Throwable cause) {
errors.add(cause); // Asynchronous error is flatten into an error by this operator.
} finally {
latch.countdown();
}
});
}
latch.await();
if (!errors.isEmpty()) {
createAndThrowACompositeException(errors);
}
mapper - Function to convert each item emitted by this Publisher into a Completable.Completable that terminates successfully if all the intermediate Completables have
terminated successfully or any one of them has terminated with a failure.flatMapMergeSingleDelayError(Function, int)public final Completable flatMapCompletableDelayError(Function<? super T,? extends Completable> mapper, int maxConcurrency)
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure.
If any mapped Completable terminates with an error the returned Completable will not immediately
terminate. Instead, it will wait for this Publisher and all mapped Completables to terminate.
This method is similar to map(Function) but the result is asynchronous, and provides a data
transformation in sequential programming similar to:
Executor e = ...;
List<Throwable> errors = ...; // assume this is thread safe
CountDownLatch latch = new CountDownLatch(tResults.size());
for (T t : tResults) {
// Note that flatMap process results in parallel.
e.execute(() -> {
try {
mapper.apply(t); // Asynchronous result is flattened by this operator.
} catch (Throwable cause) {
errors.add(cause); // Asynchronous error is flatten into an error by this operator.
} finally {
latch.countdown();
}
});
}
latch.await();
if (!errors.isEmpty()) {
createAndThrowACompositeException(errors);
}
mapper - Function to convert each item emitted by this Publisher into a Completable.maxConcurrency - Maximum active Completables at any time.Completable that terminates successfully if all the intermediate Completables have
terminated successfully or any one of them has terminated with a failure.flatMapMergeSingleDelayError(Function, int)public final Completable flatMapCompletableDelayError(Function<? super T,? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Publisher into a Completable and flatten all signals
such that the returned Completable terminates when all mapped Completables have terminated
successfully or any one of them has terminated with a failure.
If any mapped Completable terminates with an error the returned Completable will not immediately
terminate. Instead, it will wait for this Publisher and all mapped Completables to terminate.
This method is similar to map(Function) but the result is asynchronous, and provides a data
transformation in sequential programming similar to:
Executor e = ...;
List<Throwable> errors = ...; // assume this is thread safe
CountDownLatch latch = new CountDownLatch(tResults.size());
for (T t : tResults) {
// Note that flatMap process results in parallel.
e.execute(() -> {
try {
mapper.apply(t); // Asynchronous result is flattened by this operator.
} catch (Throwable cause) {
errors.add(cause); // Asynchronous error is flatten into an error by this operator.
} finally {
latch.countdown();
}
});
}
latch.await();
if (!errors.isEmpty()) {
createAndThrowACompositeException(errors);
}
mapper - Function to convert each item emitted by this Publisher into a Completable.maxConcurrency - Maximum active Completables at any time.maxDelayedErrorsHint - The maximum amount of errors that will be queued. After this point exceptions maybe
discarded to reduce memory consumption.Completable that terminates successfully if all the intermediate Completables have
terminated successfully or any one of them has terminated with a failure.flatMapMergeSingleDelayError(Function, int)public final <R> Publisher<R> flatMapConcatIterable(Function<? super T,? extends Iterable<? extends R>> mapper)
Publisher that flattens each element returned by the Iterable.iterator() from
mapper.
The mapper Function will only be called when the previously returned Iterator has returned
false from Iterator.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;
R - The elements returned by the Iterable.mapper - A Function that returns an Iterable for each element.Publisher that flattens each element returned by the Iterable.iterator() from
mapper. The results will be sequential for each Iterator, and overall for all calls to
Iterable.iterator()public final Publisher<T> whenOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe)
onSubscribe Consumer argument when
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher.
The order in which onSubscribe will be invoked relative to
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is undefined. If you need strict ordering see
beforeOnSubscribe(Consumer) and afterOnSubscribe(Consumer).
onSubscribe - Invoked when PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.beforeOnNext(Consumer),
afterOnNext(Consumer)public final Publisher<T> whenOnNext(Consumer<? super T> onNext)
onNext Consumer argument when PublisherSource.Subscriber.onNext(Object) is called for
PublisherSource.Subscribers of the returned Publisher.
The order in which onNext will be invoked relative to PublisherSource.Subscriber.onNext(Object) is undefined. If
you need strict ordering see beforeOnNext(Consumer) and afterOnNext(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);
}
onNext - Invoked when PublisherSource.Subscriber.onNext(Object) is called for PublisherSource.Subscribers of the returned
Publisher. MUST NOT throw.Publisher.beforeOnNext(Consumer),
afterOnNext(Consumer)public final Publisher<T> whenOnComplete(Runnable onComplete)
onComplete Runnable argument when PublisherSource.Subscriber.onComplete() is called for
PublisherSource.Subscribers of the returned Publisher.
The order in which onComplete will be invoked relative to PublisherSource.Subscriber.onComplete() is undefined.
If you need strict ordering see beforeOnComplete(Runnable) and afterOnComplete(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);
onComplete - Invoked when PublisherSource.Subscriber.onComplete() is called for PublisherSource.Subscribers of the
returned Publisher. MUST NOT throw.Publisher.beforeOnComplete(Runnable),
afterOnComplete(Runnable)public final Publisher<T> whenOnError(Consumer<Throwable> onError)
onError Consumer argument when PublisherSource.Subscriber.onError(Throwable) is called for
PublisherSource.Subscribers of the returned Publisher.
The order in which onError will be invoked relative to PublisherSource.Subscriber.onError(Throwable) is
undefined. If you need strict ordering see beforeOnError(Consumer) and
afterOnError(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);
}
onError - Invoked before PublisherSource.Subscriber.onError(Throwable) is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.beforeOnError(Consumer),
afterOnError(Consumer)public final Publisher<T> whenFinally(Runnable doFinally)
whenFinally Runnable argument exactly once, when any of the following terminal
methods are called:
PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher.
The order in which whenFinally will be invoked relative to the above methods is undefined. If you need
strict ordering see beforeFinally(Runnable) and afterFinally(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();
}
doFinally - Invoked exactly once, when any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.beforeFinally(Runnable),
afterFinally(Runnable)public final Publisher<T> whenFinally(TerminalSignalConsumer doFinally)
whenFinally TerminalSignalConsumer argument when any of the
following terminal methods are called:
PublisherSource.Subscriber.onComplete() - invokes TerminalSignalConsumer.onComplete()PublisherSource.Subscriber.onError(Throwable) - invokes TerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher.
The order in which whenFinally will be invoked relative to the above methods is undefined. If you need
strict ordering see beforeFinally(TerminalSignalConsumer) and
afterFinally(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();
doFinally - For each subscribe of the returned Publisher, at most one method of this
TerminalSignalConsumer will be invoked.Publisher.beforeFinally(TerminalSignalConsumer),
afterFinally(TerminalSignalConsumer)public final Publisher<T> whenRequest(LongConsumer onRequest)
onRequest LongConsumer argument when PublisherSource.Subscription.request(long) is called for
PublisherSource.Subscriptions of the returned Publisher.onRequest - Invoked when PublisherSource.Subscription.request(long) is called for PublisherSource.Subscriptions of the
returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> whenCancel(Runnable onCancel)
onCancel Runnable argument when Cancellable.cancel() is called for
Subscriptions of the returned Publisher.
The order in which whenFinally will be invoked relative to Cancellable.cancel() is undefined. If
you need strict ordering see beforeCancel(Runnable) and afterCancel(Runnable).
onCancel - Invoked when Cancellable.cancel() is called for Subscriptions of the returned
Publisher. MUST NOT throw.Publisher.beforeCancel(Runnable),
afterCancel(Runnable)@Deprecated public final Publisher<T> idleTimeout(long duration, TimeUnit unit)
timeout(long, TimeUnit).Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.unit - The units for duration.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.timeout(long, TimeUnit, io.servicetalk.concurrent.Executor)@Deprecated public final Publisher<T> idleTimeout(Duration duration)
timeout(Duration)Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled
and the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.timeout(long, TimeUnit, io.servicetalk.concurrent.Executor)@Deprecated public final Publisher<T> idleTimeout(long duration, TimeUnit unit, Executor timeoutExecutor)
timeout(long, TimeUnit, io.servicetalk.concurrent.Executor).Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.unit - The units for duration.timeoutExecutor - The Executor to use for managing the timer notifications.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.@Deprecated public final Publisher<T> idleTimeout(Duration duration, Executor timeoutExecutor)
timeout(Duration, io.servicetalk.concurrent.Executor).Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.timeoutExecutor - The Executor to use for managing the timer notifications.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.public final Publisher<T> timeout(long duration, TimeUnit unit)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.unit - The units for duration.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.timeout(long, TimeUnit, io.servicetalk.concurrent.Executor)public final Publisher<T> timeout(Duration duration)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled
and the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.timeout(long, TimeUnit, io.servicetalk.concurrent.Executor)public final Publisher<T> timeout(long duration, TimeUnit unit, Executor timeoutExecutor)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.unit - The units for duration.timeoutExecutor - The Executor to use for managing the timer notifications.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.public final Publisher<T> timeout(Duration duration, Executor timeoutExecutor)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between adjacent PublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration which is allowed to elapse between PublisherSource.Subscriber.onNext(Object) calls.timeoutExecutor - The Executor to use for managing the timer notifications.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between PublisherSource.Subscriber.onNext(Object) calls.public final Publisher<T> timeoutTerminal(Duration duration)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination. The timer starts
when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration during which the Publisher must complete.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination.public final Publisher<T> timeoutTerminal(Duration duration, Executor timeoutExecutor)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination. The timer starts
when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration during which the Publisher must complete.timeoutExecutor - The Executor to use for managing the timer notifications.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination.public final Publisher<T> timeoutTerminal(long duration, TimeUnit unit)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination. The timer starts
when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration during which the Publisher must complete.unit - The units for duration.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination.public final Publisher<T> timeoutTerminal(long duration, TimeUnit unit, Executor timeoutExecutor)
Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination. The timer starts
when the returned Publisher is subscribed.
In the event of timeout any PublisherSource.Subscription from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) will be cancelled and
the associated PublisherSource.Subscriber will be terminated.
duration - The time duration during which the Publisher must complete.unit - The units for duration.timeoutExecutor - The Executor to use for managing the timer notifications.Publisher that will mimic the signals of this Publisher but will terminate with a
TimeoutException if time duration elapses between subscribe and termination.public final Publisher<T> concat(Publisher<? extends T> next)
next Publisher after this 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;
public final Publisher<T> concat(Single<? extends T> next)
next Single after this 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;
public final Publisher<T> concat(Completable next)
next Completable after this Publisher terminates
successfully. Any error from this Publisher and next Completable is forwarded to
the returned Publisher.
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;
next - Completable to wait for completion after this Publisher terminates
successfully.Publisher that emits all items from this Publisher and then awaits successful
completion of next Completable.public final Publisher<T> retry(BiIntPredicate<Throwable> shouldRetry)
Publisher if an error is emitted and the passed BiIntPredicate returns
true.
This method may result in aThis method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowErrorif 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;
}
}
}
shouldRetry - BiIntPredicate that given the retry count and the most recent Throwable
emitted from this
Publisher determines if the operation should be retried.Publisher that emits all items from this Publisher and re-subscribes if an error is
emitted if the passed BiIntPredicate returned true.public final Publisher<T> retryWhen(BiIntFunction<Throwable,? extends Completable> retryWhen)
Publisher if an error is emitted and the Completable returned by the
supplied BiIntFunction completes successfully. If the returned Completable emits an error, the
returned Publisher terminates with that error.
This method may result in aThis method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif 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;
}
}
}
retryWhen - BiIntFunction that given the retry count and the most recent Throwable emitted
from this Publisher returns a Completable. If this Completable emits an error, that error
is emitted from the returned Publisher, otherwise, original Publisher is re-subscribed when this
Completable completes.Publisher that emits all items from this Publisher and re-subscribes if an error is
emitted and Completable returned by BiIntFunction completes successfully.public final Publisher<T> repeat(IntPredicate shouldRepeat)
Publisher when it completes and the passed IntPredicate returns
true.
This method may result in aThis method provides a means to repeat an operation multiple times and in sequential programming is similar to:StackOverflowErrorif 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;
shouldRepeat - IntPredicate that given the repeat count determines if the operation should be
repeated.Publisher that emits all items from this Publisher and re-subscribes when it completes
if the passed IntPredicate returns true.public final Publisher<T> repeatWhen(IntFunction<? extends Completable> repeatWhen)
Publisher when it completes and the Completable returned by the supplied
IntFunction completes successfully. If the returned Completable emits an error, the returned
Publisher is completed.
This method may result in aThis method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif 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;
repeatWhen - IntFunction that given the repeat count returns a Completable.
If this Completable emits an error repeat is terminated, otherwise, original Publisher is
re-subscribed when this Completable completes.Publisher that emits all items from this Publisher and re-subscribes if an error is
emitted and Completable returned by IntFunction completes successfully.public final Publisher<T> takeAtMost(long numElements)
numElements elements from this Publisher.
If no terminal event is received before receiving numElements elements, PublisherSource.Subscription for the
PublisherSource.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;
numElements - Number of elements to take.Publisher that emits at most numElements elements from this Publisher.public final Publisher<T> takeWhile(Predicate<? super T> predicate)
Predicate is true and then cancel PublisherSource.Subscription of this
Publisher once it returns false.
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;
predicate - Predicate that is checked before emitting any item to a PublisherSource.Subscriber.
If this predicate returns true, that item is emitted, else PublisherSource.Subscription is cancelled.Publisher that only emits the items as long as the Predicate.test(Object) method
returns true.public final Publisher<T> takeUntil(Completable until)
Completable 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;
until - Completable, termination of which, terminates the returned Publisher.Publisher that only emits the items till until Completable is completed.public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T,? extends Key> keySelector, int groupMaxQueueSize)
Publisher into dynamically generated GroupedPublishers.
Item to group association is done by keySelector Function. If the selector selects a key which is
previously seen and its associated PublisherSource.Subscriber has not yet cancelled its PublisherSource.Subscription, this item
is sent to that PublisherSource.Subscriber. Otherwise a new GroupedPublisher is created and emitted from the
returned Publisher.
Flow control
MultiplePublisherSource.Subscribers (for multiple GroupedPublishers) request items individually from this
Publisher. Since, there is no way for a PublisherSource.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 the maxQueuePerGroup argument.
Cancellation
If thePublisherSource.Subscriber of the returned Publisher cancels its PublisherSource.Subscription, then all active
GroupedPublishers will be terminated with an error and the PublisherSource.Subscription to this Publisher
will be cancelled.
PublisherSource.Subscribers of individual GroupedPublishers can cancel their PublisherSource.Subscriptions at any point.
If any new item is emitted for the cancelled GroupedPublisher, a new GroupedPublisher will be
emitted from the returned Publisher. Any queued items for a cancelled PublisherSource.Subscriber for a
GroupedPublisher will be discarded and hence will not be emitted if the same GroupedPublisher 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;
Key - Type of GroupedPublisher keys.keySelector - Function to assign an item emitted by this Publisher to a
GroupedPublisher.groupMaxQueueSize - Maximum number of new groups that will be queued due to the PublisherSource.Subscriber of the
Publisher returned from this method not requesting enough via PublisherSource.Subscription.request(long).Publisher that emits GroupedPublishers for new keys as emitted by
keySelector Function.public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T,? extends Key> keySelector, int groupMaxQueueSize, int expectedGroupCountHint)
Publisher into dynamically generated GroupedPublishers. Item to group
association is done by keySelector Function. If the selector selects a key which is previously
seen and its associated PublisherSource.Subscriber has not yet cancelled its PublisherSource.Subscription, this item is sent to
that PublisherSource.Subscriber. Otherwise a new GroupedPublisher is created and emitted from the returned
Publisher.
Flow control
MultiplePublisherSource.Subscribers (for multiple GroupedPublishers) request items individually from this
Publisher. Since, there is no way for a PublisherSource.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 the maxQueuePerGroup argument.
Cancellation
If thePublisherSource.Subscriber of the returned Publisher cancels its PublisherSource.Subscription, then all active
GroupedPublishers will be terminated with an error and the PublisherSource.Subscription to this Publisher
will be cancelled.
PublisherSource.Subscribers of individual GroupedPublishers can cancel their PublisherSource.Subscriptions at any point.
If any new item is emitted for the cancelled GroupedPublisher, a new GroupedPublisher will be
emitted from the returned Publisher. Any queued items for a cancelled PublisherSource.Subscriber for a
GroupedPublisher will be discarded and hence will not be emitted if the same GroupedPublisher 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;
Key - Type of GroupedPublisher keys.keySelector - Function to assign an item emitted by this Publisher to a
GroupedPublisher.groupMaxQueueSize - Maximum number of new groups that will be queued due to the PublisherSource.Subscriber of the
Publisher returned from this method not requesting enough via PublisherSource.Subscription.request(long).expectedGroupCountHint - Expected number of groups that would be emitted by this Publisher.
This is just a hint for internal data structures and does not have to be precise.Publisher that emits GroupedPublishers for new keys as emitted by
keySelector Function.public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T,? extends Iterator<? extends Key>> keySelector, int groupMaxQueueSize)
groupBy(Function, int) except that the keySelector 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;
Key - Type of GroupedPublisher keys.keySelector - Function to assign an item emitted by this Publisher to multiple
GroupedPublishers.groupMaxQueueSize - Maximum number of new groups that will be queued due to the PublisherSource.Subscriber of the
Publisher returned from this method not requesting enough via PublisherSource.Subscription.request(long).Publisher that emits GroupedPublishers for new keys as emitted by
keySelector Function.groupBy(Function, int)public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T,? extends Iterator<? extends Key>> keySelector, int groupMaxQueueSize, int expectedGroupCountHint)
groupBy(Function, int) except that the keySelector 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;
Key - Type of GroupedPublisher keys.keySelector - Function to assign an item emitted by this Publisher to multiple
GroupedPublishers.groupMaxQueueSize - Maximum number of new groups that will be queued due to the PublisherSource.Subscriber of the
Publisher returned from this method not requesting enough via PublisherSource.Subscription.request(long).expectedGroupCountHint - Expected number of groups that would be emitted by this Publisher.
This is just a hint for internal data structures and does not have to be precise.Publisher that emits GroupedPublishers for new keys as emitted by
keySelector Function.groupBy(Function, int)public final Publisher<T> multicastToExactly(int expectedSubscribers)
Publisher that multicasts all the signals to exactly expectedSubscribers.
Depending on PublisherSource.Subscription.request(long) demand it is possible that data maybe queued before being
delivered to each PublisherSource.Subscriber! For example if there are 2 PublisherSource.Subscribers and the first calls
request(10), and the second only calls
request(1), then 9 elements will be queued to deliver to second when more
PublisherSource.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;
public final Publisher<T> multicastToExactly(int expectedSubscribers, int maxQueueSize)
Publisher that allows exactly expectedSubscribers subscribes.
The events from this Publisher object will be delivered to each
PublisherSource.Subscriber.
Depending on PublisherSource.Subscription.request(long) demand it is possible that data maybe queued before being
delivered to each PublisherSource.Subscriber! For example if there are 2 PublisherSource.Subscribers and the first calls
request(10), and the second only calls
request(10), then 9 elements will be queued to deliver to second when more
PublisherSource.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;
expectedSubscribers - The number of expected subscribe calls required on the returned Publisher
before subscribing to this Publisher.maxQueueSize - The maximum number of PublisherSource.Subscriber.onNext(Object) events that will be queued if there
is no demand for data before the PublisherSource.Subscriber will be discarded.Publisher that allows exactly expectedSubscribers subscribes.public final <BC extends BufferStrategy.Accumulator<T,B>,B> Publisher<B> buffer(BufferStrategy<T,BC,B> strategy)
Publisher that buffers items from this Publisher and emit those buffers instead of the
individual items.
In sequential programming this is similar to the following:
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;
Notes:
Publisher does not emit items within the boundary,
it's expected it will emit an empty accumulated value as the result of
accumulating nothing. Use filter(Predicate) operator if empty accumulations have to be discarded.
boundary is emitted while this operator
accumulates or emits the
next result of accumulation, those boundaries will be
discarded without invoking BufferStrategy.Accumulator.finish() method.BC - Type of the BufferStrategy.Accumulator to buffer items from this Publisher.B - Type of the buffer emitted from the returned Publisher.strategy - A BufferStrategy to use for buffering items from this Publisher.Publisher that buffers items from this Publisher and emit those buffers instead of the
individual items.public final Publisher<T> beforeOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe)
onSubscribe Consumer argument before
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher.onSubscribe - Invoked before
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeOnNext(Consumer<? super T> onNext)
onNext Consumer argument before PublisherSource.Subscriber.onNext(Object) is
called for PublisherSource.Subscribers of the returned Publisher.
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);
onNext - Invoked before PublisherSource.Subscriber.onNext(Object) is called for PublisherSource.Subscribers
of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeOnError(Consumer<Throwable> onError)
onError Consumer argument before
PublisherSource.Subscriber.onError(Throwable) is called for PublisherSource.Subscribers of the returned Publisher.
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);
}
onError - Invoked before PublisherSource.Subscriber.onError(Throwable) is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeOnComplete(Runnable onComplete)
onComplete Runnable argument before PublisherSource.Subscriber.onComplete()
is called for PublisherSource.Subscribers of the returned Publisher.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher();
onComplete.run();
nextOperation(results);
onComplete - Invoked before PublisherSource.Subscriber.onComplete() is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeRequest(LongConsumer onRequest)
onRequest LongConsumer argument before
PublisherSource.Subscription.request(long) is called for PublisherSource.Subscriptions of the returned Publisher.onRequest - Invoked before PublisherSource.Subscription.request(long) is called for
PublisherSource.Subscriptions of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeCancel(Runnable onCancel)
onCancel Runnable argument before Cancellable.cancel() is
called for PublisherSource.Subscriptions of the returned Publisher.onCancel - Invoked before Cancellable.cancel() is called for
PublisherSource.Subscriptions of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeFinally(Runnable doFinally)
beforeFinally Runnable argument before any of the following terminal
methods are called:
PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher.
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
}
doFinally - Invoked before any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> beforeFinally(TerminalSignalConsumer doFinally)
beforeFinally TerminalSignalConsumer argument
before any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete() - invokes TerminalSignalConsumer.onComplete()PublisherSource.Subscriber.onError(Throwable) - invokes TerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher.
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
doFinally - For each subscribe of the returned Publisher, at most one method of this
TerminalSignalConsumer will be invoked.Publisher.public final Publisher<T> beforeSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
PublisherSource.Subscriber (via the subscriberSupplier argument) on each call to subscribe and
invokes all the PublisherSource.Subscriber methods before the PublisherSource.Subscribers of the returned
Publisher.subscriberSupplier - Creates a new PublisherSource.Subscriber on each call to subscribe and invokes all the
PublisherSource.Subscriber methods before the PublisherSource.Subscribers of the returned Publisher.
PublisherSource.Subscriber methods MUST NOT throw.Publisher.public final Publisher<T> beforeSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
PublisherSource.Subscription (via the subscriptionSupplier argument) on each call to
subscribe and invokes all the PublisherSource.Subscription methods before the PublisherSource.Subscriptions of
the returned Publisher.subscriptionSupplier - Creates a new PublisherSource.Subscription on each call to subscribe and invokes all the
PublisherSource.Subscription methods before the PublisherSource.Subscriptions of the returned
Publisher. PublisherSource.Subscription methods MUST NOT throw.Publisher.public final Publisher<T> afterOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe)
onSubscribe Consumer argument after
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for PublisherSource.Subscribers of the returned
Publisher.onSubscribe - Invoked after
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterOnNext(Consumer<? super T> onNext)
onNext Consumer argument after PublisherSource.Subscriber.onNext(Object) is
called for PublisherSource.Subscribers of the returned Publisher.
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);
}
onNext - Invoked after PublisherSource.Subscriber.onNext(Object) is called for PublisherSource.Subscribers
of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterOnError(Consumer<Throwable> onError)
onError Consumer argument after
PublisherSource.Subscriber.onError(Throwable) is called for PublisherSource.Subscribers of the returned Publisher.
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);
}
onError - Invoked after PublisherSource.Subscriber.onError(Throwable) is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterOnComplete(Runnable onComplete)
onComplete Runnable argument after PublisherSource.Subscriber.onComplete()
is called for PublisherSource.Subscribers of the returned Publisher.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher();
nextOperation(results);
onComplete.run();
onComplete - Invoked after PublisherSource.Subscriber.onComplete() is called for
PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterRequest(LongConsumer onRequest)
onRequest LongConsumer argument after
PublisherSource.Subscription.request(long) is called for PublisherSource.Subscriptions of the returned Publisher.onRequest - Invoked after PublisherSource.Subscription.request(long) is called for
PublisherSource.Subscriptions of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterCancel(Runnable onCancel)
onCancel Runnable argument after Cancellable.cancel() is
called for PublisherSource.Subscriptions of the returned Publisher.onCancel - Invoked after Cancellable.cancel() is called for PublisherSource.Subscriptions
of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterFinally(Runnable doFinally)
afterFinally Runnable argument after any of the following terminal
methods are called:
PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher.
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();
}
doFinally - Invoked after any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher. MUST NOT throw.Publisher.public final Publisher<T> afterFinally(TerminalSignalConsumer doFinally)
afterFinally TerminalSignalConsumer argument
after any of the following terminal methods are called:
PublisherSource.Subscriber.onComplete() - invokes TerminalSignalConsumer.onComplete()PublisherSource.Subscriber.onError(Throwable) - invokes TerminalSignalConsumer.onError(Throwable)Cancellable.cancel() - invokes TerminalSignalConsumer.cancel()PublisherSource.Subscriptions/PublisherSource.Subscribers of the returned Publisher.
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();
doFinally - For each subscribe of the returned Publisher, at most one method of this
TerminalSignalConsumer will be invoked.Publisher.public final Publisher<T> afterSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
PublisherSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes all the PublisherSource.Subscriber methods after the PublisherSource.Subscribers of the returned
Publisher.subscriberSupplier - Creates a new PublisherSource.Subscriber for each new subscribe and invokes all the
PublisherSource.Subscriber methods after the PublisherSource.Subscribers of the returned Publisher.
PublisherSource.Subscriber methods MUST NOT throw.Publisher.public final Publisher<T> whenSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
PublisherSource.Subscriber (via the subscriberSupplier argument) for each new subscribe and
invokes methods on that PublisherSource.Subscriber when the corresponding methods are called for PublisherSource.Subscribers of
the returned Publisher.subscriberSupplier - Creates a new PublisherSource.Subscriber for each new subscribe and invokes methods on that
PublisherSource.Subscriber when the corresponding methods are called for PublisherSource.Subscribers of the returned
Publisher. PublisherSource.Subscriber methods MUST NOT throw.Publisher.public final Publisher<T> afterSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
PublisherSource.Subscription (via the subscriptionSupplier argument) for each new subscribe and
invokes all the PublisherSource.Subscription methods after the PublisherSource.Subscriptions of the returned
Publisher.subscriptionSupplier - Creates a new PublisherSource.Subscription for each new subscribe and invokes all the
PublisherSource.Subscription methods after the PublisherSource.Subscriptions of the returned Publisher.
PublisherSource.Subscription methods MUST NOT throw.Publisher.public final Publisher<T> whenSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
PublisherSource.Subscription (via the subscriptionSupplier argument) for each new subscribe and
invokes all the PublisherSource.Subscription methods when the corresponding methods are called for PublisherSource.Subscriptions
of the returned Publisher.subscriptionSupplier - Creates a new PublisherSource.Subscription for each new subscribe and invokes all the
PublisherSource.Subscription methods when the PublisherSource.Subscriptions of the returned Publisher.
PublisherSource.Subscription methods MUST NOT throw.Publisher.public final Cancellable forEach(Consumer<? super T> forEach)
Publisher and invokes forEach Consumer for each item emitted by this
Publisher.
This will request Long.MAX_VALUE from the PublisherSource.Subscription.
From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher();
results.iterator().forEachRemaining(forEach);
forEach - Consumer to invoke for each PublisherSource.Subscriber.onNext(Object).Cancellable used to invoke Cancellable.cancel() on the parameter of
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) for this Publisher.public final Publisher<T> publishOn(Executor executor)
Publisher that will use the passed Executor to invoke all PublisherSource.Subscriber
methods.
This method does not override preceding Executors, if any, specified for this
Publisher. Only subsequent operations, if any, added in this execution chain will use this
Executor. If such an override is required, publishOnOverride(Executor) can be used.@Deprecated public final Publisher<T> publishOnOverride(Executor executor)
publishOn(Executor)
and/or using Executor.execute(Runnable) for offloading.Publisher that will use the passed Executor to invoke all PublisherSource.Subscriber
methods.
This method overrides preceding Executors, if any, specified for this Publisher.
That is to say preceding and subsequent operations for this execution chain will use this Executor.
If such an override is not required, publishOn(Executor) can be used.public final Publisher<T> subscribeOn(Executor executor)
Publisher that will use the passed Executor to invoke the following methods:
PublisherSource.Subscription methods.handleSubscribe(PublisherSource.Subscriber) method.Executors, if any, specified for this
Publisher. Only subsequent operations, if any, added in this execution chain will use this
Executor. If such an override is required, subscribeOnOverride(Executor) can be used.executor - Executor to use.Publisher that will use the passed Executor to invoke all methods of
PublisherSource.Subscription and handleSubscribe(PublisherSource.Subscriber).@Deprecated public final Publisher<T> subscribeOnOverride(Executor executor)
subscribeOn(Executor)
and/or using Executor.execute(Runnable) for offloading.Publisher that will use the passed Executor to invoke the following methods:
PublisherSource.Subscription methods.handleSubscribe(PublisherSource.Subscriber) method.Executors, if any, specified for this Publisher.
That is to say preceding and subsequent operations for this execution chain will use this Executor.
If such an override is not required, subscribeOn(Executor) can be used.@Deprecated public final Publisher<T> publishAndSubscribeOn(Executor executor)
subscribeOn(Executor) and publishOn(Executor) operators instead.Publisher that will use the passed Executor to invoke the following methods:
PublisherSource.Subscriber methods.PublisherSource.Subscription methods.handleSubscribe(PublisherSource.Subscriber) method.Executors, if any, specified for this
Publisher. Only subsequent operations, if any, added in this execution chain will use this
Executor. If such an override is required, publishAndSubscribeOnOverride(Executor) can be used.executor - Executor to use.Publisher that will use the passed Executor to invoke all methods
PublisherSource.Subscriber, PublisherSource.Subscription and handleSubscribe(PublisherSource.Subscriber).@Deprecated public final Publisher<T> publishAndSubscribeOnOverride(Executor executor)
publishAndSubscribeOn(Executor) and/or using Executor.execute(Runnable) for offloading.Publisher that will use the passed Executor to invoke the following methods:
PublisherSource.Subscriber methods.PublisherSource.Subscription methods.handleSubscribe(PublisherSource.Subscriber) method.Executors, if any, specified for this Publisher.
That is to say preceding and subsequent operations for this execution chain will use this Executor.
If such an override is not required, publishAndSubscribeOn(Executor) can be used.public final Publisher<T> subscribeShareContext()
Publisher is subscribed to, the AsyncContext will be shared
instead of making a copy.
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.
Publisher that will share the AsyncContext instead of making a
copy when subscribed to.public final <R> Publisher<R> liftSync(PublisherOperator<? super T,? extends R> operator)
Returns a Publisher which when subscribed, the operator argument will be used to wrap the
PublisherSource.Subscriber before subscribing to this Publisher.
Publisher<X> pub = ...;
pub.map(..) // A
.liftSync(original -> modified)
.filter(..) // B
The original -> modified "operator" MUST be "synchronous" in that it does not interact
with the original PublisherSource.Subscriber from outside the modified PublisherSource.Subscriber or PublisherSource.Subscription
threads. That is to say this operator will not impact the Executor constraints already in place between
A and B above. If you need asynchronous behavior, or are unsure, see
liftAsync(PublisherOperator).R - Type of the items emitted by the returned Publisher.operator - The custom operator logic. The input is the "original" PublisherSource.Subscriber to this
Publisher and the return is the "modified" PublisherSource.Subscriber that provides custom operator business
logic.Publisher which when subscribed, the operator argument will be used to wrap the
PublisherSource.Subscriber before subscribing to this Publisher.liftAsync(PublisherOperator)public final <R> Single<R> liftSyncToSingle(PublisherToSingleOperator<? super T,? extends R> operator)
Returns a Single which when subscribed, the operator argument will be used to convert between the
SingleSource.Subscriber to a PublisherSource.Subscriber before subscribing to this Publisher.
Publisher<X> pub = ...;
pub.map(..) // A
.liftSync(original -> modified)
.filter(..) // B - we have converted to Single now!
The original -> modified "operator" MUST be "synchronous" in that it does not interact
with the original PublisherSource.Subscriber from outside the modified PublisherSource.Subscriber or PublisherSource.Subscription
threads. That is to say this operator will not impact the Executor constraints already in place between
A and B above. If you need asynchronous behavior, or are unsure, don't use this operator.R - Type of the items emitted by the returned Single.operator - The custom operator logic. The input is the "original" SingleSource.Subscriber to the
returned Single and the return is the "modified" PublisherSource.Subscriber that provides custom operator
business logic on this Publisher.Single which when subscribed, the operator argument will be used to convert the
SingleSource.Subscriber to a PublisherSource.Subscriber before subscribing to this Publisher.public final <R> Publisher<R> liftAsync(PublisherOperator<? super T,? extends R> operator)
Returns a Publisher which will wrap the PublisherSource.Subscriber using the provided
operator argument before subscribing to this Publisher.
Publisher<X> pub = ...;
pub.map(..) // A
.liftAsync(original -> modified)
.filter(..) // B
The original -> modified "operator" MAY be "asynchronous" in that it may interact with the original
PublisherSource.Subscriber from outside the modified PublisherSource.Subscriber or PublisherSource.Subscription threads. More
specifically:
This behavior exists to prevent blocking code negatively impacting the thread that powers the upstream source of
data (e.g. an EventLoop).R - Type of the items emitted by the returned Publisher.operator - The custom operator logic. The input is the "original" PublisherSource.Subscriber to this
Publisher and the return is the "modified" PublisherSource.Subscriber that provides custom operator business
logic.Publisher which when subscribed, the operator argument will be used to wrap the
PublisherSource.Subscriber before subscribing to this Publisher.liftSync(PublisherOperator)public final Single<T> firstOrElse(Supplier<T> defaultValueSupplier)
defaultValueSupplier - A Supplier of default value if this Publisher did not emit any item.Single that will contain the first item emitted from the this Publisher.
If the source Publisher does not emit any item, then the returned Single will contain the value
as returned by the passed Supplier.public final Single<T> firstOrError()
Publisher emits exactly a single PublisherSource.Subscriber.onNext(Object) to its
PublisherSource.Subscriber. If this Publisher terminates without emitting any
items a NoSuchElementException will be signaled and if this Publisher emits more than one item,
an IllegalArgumentException will be signaled. Any error emitted by this Publisher will be
forwarded to the returned Single.public final Completable ignoreElements()
Publisher and forwards the termination signal to the returned
Completable.Completable that mirrors the terminal signal from this Publisher.public final Completable completableOrError()
Publisher to a Completable. If this Publisher emits any
PublisherSource.Subscriber.onNext(Object) signals the resulting Completable will be terminated with a
IllegalArgumentException.Completable that mirrors the terminal signal from this Publisher, and terminates in
error if an PublisherSource.Subscriber.onNext(Object) signals.public final <R> Single<R> collect(Supplier<? extends R> resultFactory, BiFunction<? super R,? super T,R> collector)
Publisher into a single item.R - Type of the reduced item.resultFactory - Factory for the result which collects all items emitted by this Publisher.
This will be called every time the returned Single is subscribed.collector - Invoked for every item emitted by the source Publisher and returns the same or altered
result object.Single that completes with the single result or any error emitted by the source
Publisher.public final Future<Collection<T>> toFuture()
Publisher into a Future with a Collection containing the elements of this
Publisher upon successful termination. If this Publisher terminates in an error, then the
intermediate Collection will be discarded and the Future will complete exceptionally.Future with a Collection containing the elements of this Publisher upon
successful termination.toFuture(Supplier, BiFunction)public final <R> Future<R> toFuture(Supplier<? extends R> resultFactory,
BiFunction<? super R,? super T,R> reducer)
Publisher into a Future of type R which represents all elements of this
Publisher upon successful termination. If this Publisher terminates in an error, then the
intermediate R will be discarded and the Future will complete exceptionally.R - Type of the reduced item.resultFactory - Factory for the result which collects all items emitted by this Publisher.reducer - Invoked for every item emitted by the source Publisher and returns the same or altered
result object.Future of type R which represents all elements of this Publisher upon
successful termination.public final CompletionStage<Collection<T>> toCompletionStage()
Publisher into a CompletionStage with a Collection containing the elements
of this Publisher upon successful termination. If this Publisher terminates in an error, then the
intermediate Collection will be discarded and the CompletionStage will complete exceptionally.CompletionStage with a Collection containing the elements of this Publisher
upon successful termination.toCompletionStage(Supplier, BiFunction)public final <R> CompletionStage<R> toCompletionStage(Supplier<? extends R> resultFactory,
BiFunction<? super R,? super T,R> reducer)
Publisher into a CompletionStage of type R which represents all elements of
this Publisher upon successful termination. If this Publisher terminates in an error, then the
intermediate R will be discarded and the CompletionStage will complete exceptionally.R - Type of the reduced item.resultFactory - Factory for the result which collects all items emitted by this Publisher.reducer - Invoked for every item emitted by the source Publisher and returns the same or altered
result object.CompletionStage of type R which represents all elements of this Publisher upon
successful termination.public final InputStream toInputStream(Function<? super T,byte[]> serializer)
this Publisher and converts all signals received by the PublisherSource.Subscriber to the
returned InputStream following the below rules:
PublisherSource.Subscription received by PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is used to
request more data when required. If the returned InputStream is closed, PublisherSource.Subscription is
cancelled and any unread data is disposed.PublisherSource.Subscriber.onNext(Object) are converted to a byte[] using the
passed serializer. These bytes are available to be read from the InputStreamThrowable received by PublisherSource.Subscriber.onError(Throwable) is thrown (wrapped in an
IOException) when data is read from the returned InputStream. This error will be thrown
only after draining all queued data, if any.PublisherSource.Subscriber.onComplete() is called, returned InputStream'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 returned InputStream. In order to increase responsiveness of the
InputStream some amount of buffering may be done. Use toInputStream(Function, int) to manage
capacity of this buffer.serializer - Function that is invoked for every item emitted by this Publisher.InputStream that emits all data emitted by this Publisher. If this
Publisher terminates with an error, same error is thrown (wrapped in an IOException) from the
returned InputStreams read methods after emitting all received data.public final InputStream toInputStream(Function<? super T,byte[]> serializer, int queueCapacity)
this Publisher and converts all signals received by the PublisherSource.Subscriber to the
returned InputStream following the below rules:
PublisherSource.Subscription received by PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is used to
request more data when required. If the returned InputStream is closed, PublisherSource.Subscription is
cancelled and any unread data is disposed.PublisherSource.Subscriber.onNext(Object) are convertedto a byte[] using the
passed serializer. These bytes are available to be read from the InputStreamThrowable received by PublisherSource.Subscriber.onError(Throwable) is thrown (wrapped in an
IOException) when data is read from the returned InputStream. This error will be thrown
only after draining all queued data, if any.PublisherSource.Subscriber.onComplete() is called, returned InputStream'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 returned InputStream. In order to increase responsiveness of the InputStream
some amount of buffering may be done. queueCapacity can be used to bound this buffer.serializer - Function that is invoked for every item emitted by this Publisher.queueCapacity - Hint for the capacity of the intermediary queue that stores items that are emitted by
this Publisher but has not yet been read from the returned InputStream.InputStream that emits all data emitted by this Publisher. If this
Publisher terminates with an error, same error is thrown (wrapped in an IOException) from the
returned InputStreams read methods after emitting all received data.public final BlockingIterable<T> toIterable()
this Publisher to an BlockingIterable. Every time
BlockingIterable.iterator() is called on the returned BlockingIterable, this
Publisher is subscribed following the below rules:
PublisherSource.Subscription received by PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is used to
request more data when required.PublisherSource.Subscriber.onNext(Object) is returned from a call to
BlockingIterator.next().Throwable received by PublisherSource.Subscriber.onError(Throwable) is thrown (wrapped in a
RuntimeException if required) when BlockingIterator.next() is called. This error will be
thrown only after draining all queued data, if any.PublisherSource.Subscriber.onComplete() is called, returned BlockingIterators
Iterator.hasNext() will return false BlockingIterator.next() will throw
NoSuchElementException. 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 of
Iterator.hasNext() from the returned BlockingIterable. In order to increase responsiveness of
the Iterator some amount of buffering may be done. Use toIterable(int) to manage capacity of
this buffer.
Blocking
The returnedBlockingIterator from the returned BlockingIterable will block on
Iterator.hasNext() and BlockingIterator.next() if no data is available. This operator may
try to reduce this blocking by requesting data ahead of time.public final BlockingIterable<T> toIterable(int queueCapacityHint)
this Publisher to an BlockingIterable. Every time
BlockingIterable.iterator() is called on the returned BlockingIterable, this
Publisher is subscribed following the below rules:
PublisherSource.Subscription received by PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) is used to
request more data when required.PublisherSource.Subscriber.onNext(Object) is returned from a call to
BlockingIterator.next().Throwable received by PublisherSource.Subscriber.onError(Throwable) is thrown (wrapped in a
RuntimeException if required) when BlockingIterator.next(). This error will be thrown
only after draining all queued data, if any.PublisherSource.Subscriber.onComplete() is called, returned BlockingIterators
Iterator.hasNext() will return false and BlockingIterator.next() will throw
NoSuchElementException. 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 of
Iterator.hasNext() from the returned BlockingIterable. In order to increase
responsiveness of the BlockingIterator some amount of buffering may be done. queueCapacityHint
can be used to bound this buffer.
Blocking
The returnedBlockingIterator from the returned BlockingIterable will block on
Iterator.hasNext() and BlockingIterator.next() if no data is available. This operator may
try to reduce this blocking by requesting data ahead of time.queueCapacityHint - Hint for the capacity of the intermediary queue that stores items that are emitted by
this Publisher but has not yet been returned from the BlockingIterator.BlockingIterable representing this Publisher. Every time
BlockingIterable.iterator() is invoked on the BlockingIterable, this Publisher
is subscribed. BlockingIterators returned from this BlockingIterable do not support
Iterator.remove().protected final void subscribeInternal(PublisherSource.Subscriber<? super T> subscriber)
PublisherSource.subscribe(Subscriber) which can be used by
different implementations to subscribe.subscriber - PublisherSource.Subscriber to subscribe for the result.protected abstract void handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Publisher.subscriber - the subscriber.public static <T> Publisher<T> from(@Nullable T value)
Publisher that emits value to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().T - Type of items emitted by the returned Publisher.value - Value that the returned Publisher will emit.Publisher that emits value to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().public static <T> Publisher<T> from(@Nullable T v1, @Nullable T v2)
Publisher that emits v1 and v2 to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().T - Type of items emitted by the returned Publisher.v1 - The first value that the returned Publisher will emit.v2 - The second value that the returned Publisher will emit.Publisher that emits v1 and v2 to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().public static <T> Publisher<T> from(@Nullable T v1, @Nullable T v2, @Nullable T v3)
Publisher that emits v1, v2, and v3 to its PublisherSource.Subscriber and
then PublisherSource.Subscriber.onComplete().T - Type of items emitted by the returned Publisher.v1 - The first value that the returned Publisher will emit.v2 - The second value that the returned Publisher will emit.v3 - The third value that the returned Publisher will emit.Publisher that emits v1, v2, and v3 to its PublisherSource.Subscriber and
then PublisherSource.Subscriber.onComplete().@SafeVarargs public static <T> Publisher<T> from(T... values)
Publisher that emits all values to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().T - Type of items emitted by the returned Publisher.values - Values that the returned Publisher will emit.Publisher that emits all values to its PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().public static <T> Publisher<T> fromIterable(Iterable<? extends T> iterable)
Publisher that when subscribed will get an Iterator via Iterable.iterator()
and emit all values to the PublisherSource.Subscriber and then PublisherSource.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 associated PublisherSource.Subscriptions will
depend upon the behavior of the iterable below. Make sure the Executor for this execution chain
can tolerate this responsiveness and any blocking behavior.
T - Type of items emitted by the returned Publisher.iterable - used to obtain instances of Iterator to extract data from. Iterable.iterator()
must not return null. If this is of type BlockingIterable then any generated
BlockingIterators will have their BlockingIterator.close() method called if an error
occurs.Publisher that when subscribed will get an Iterator via Iterable.iterator()
and emit all values to the PublisherSource.Subscriber and then PublisherSource.Subscriber.onComplete().public static <T> Publisher<T> fromBlockingIterable(BlockingIterable<? extends T> iterable, LongSupplier timeoutSupplier, TimeUnit unit)
Publisher that when subscribed will get a BlockingIterator via
BlockingIterable.iterator() and emit all values to the PublisherSource.Subscriber and then
PublisherSource.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 associated PublisherSource.Subscriptions will
depend upon the behavior of the iterable below. Make sure the Executor for this execution chain
can tolerate this responsiveness and any blocking behavior.
T - Type of items emitted by the returned Publisher.iterable - used to obtain instances of Iterator to extract data from. Iterable.iterator()
must not return null. Any generated BlockingIterators will have their
BlockingIterator.close() method called if an error occurs.timeoutSupplier - A LongSupplier which provides the time duration to wait for each
interaction with iterable.unit - The time units for the timeout duration.Publisher that when subscribed will get a BlockingIterator via
BlockingIterable.iterator() and emit all values to the PublisherSource.Subscriber and then
PublisherSource.Subscriber.onComplete().public static Publisher<byte[]> fromInputStream(InputStream stream)
Publisher that when subscribed will emit all data from the InputStream to the
PublisherSource.Subscriber and then PublisherSource.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 associated PublisherSource.Subscriptions will
depend upon the behavior of the stream below. Make sure the Executor for this execution chain
can tolerate this responsiveness and any blocking behavior.
stream - provides the data in the form of byte[] to be emitted to the PublisherSource.Subscriber by the
returned Publisher. Given the blocking nature of InputStream, assume PublisherSource.Subscription.request(long) can block when the underlying InputStream blocks on InputStream.read(byte[], int, int).Publisher that when subscribed will emit all data from the InputStream to the
PublisherSource.Subscriber and then PublisherSource.Subscriber.onComplete().public static Publisher<byte[]> fromInputStream(InputStream stream, int readChunkSize)
Publisher that when subscribed will emit all data from the InputStream to the
PublisherSource.Subscriber and then PublisherSource.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 associated PublisherSource.Subscriptions will
depend upon the behavior of the stream below. Make sure the Executor for this execution chain
can tolerate this responsiveness and any blocking behavior.
stream - provides the data in the form of byte[] to be emitted to the PublisherSource.Subscriber by the
returned Publisher. Given the blocking nature of InputStream, assume PublisherSource.Subscription.request(long) can block when the underlying InputStream blocks on InputStream.read(byte[], int, int).readChunkSize - the maximum length of byte[] chunks which will be read from the InputStream
and emitted by the returned Publisher.Publisher that when subscribed will emit all data from the InputStream to the
PublisherSource.Subscriber and then PublisherSource.Subscriber.onComplete().public static Publisher<Integer> range(int begin, int end)
Publisher that when subscribed will emit all Integers within the range of
[begin, end).public static Publisher<Integer> range(int begin, int end, int stride)
Publisher that when subscribed will emit all Integers within the range of
[begin, end) with an increment of stride between each signal.begin - The beginning of the range (inclusive).end - The end of the range (exclusive).stride - The amount to increment in between each signal.Publisher that when subscribed will emit all Integers within the range of
[begin, end) with an increment of stride between each signal.public static <T> Publisher<T> empty()
Publisher that completes when subscribed without emitting any item to its
PublisherSource.Subscriber.T - Type of items emitted by the returned Publisher.Publisher that completes when subscribed without emitting any item to its
PublisherSource.Subscriber.public static <T> Publisher<T> never()
Publisher that never emits any item to its PublisherSource.Subscriber and never call any terminal
methods on it.T - Type of items emitted by the returned Publisher.Publisher that never emits any item to its PublisherSource.Subscriber and never call any terminal
methods on it.public static <T> Publisher<T> failed(Throwable cause)
Publisher that terminates its PublisherSource.Subscriber with an error without emitting any item to
it.T - Type of items emitted by the returned Publisher.cause - The Throwable that is used to terminate the PublisherSource.Subscriber.Publisher that terminates its PublisherSource.Subscriber with an error without emitting any item to
it.public static <T> Publisher<T> defer(Supplier<? extends Publisher<? extends T>> publisherSupplier)
Publisher till it is subscribed.T - Type of items emitted by the returned Publisher.publisherSupplier - Supplier to create a new Publisher every time the returned
Publisher is subscribed.Publisher that creates a new Publisher using publisherSupplier every time
it is subscribed and forwards all items and terminal events from the newly created Publisher to its
PublisherSource.Subscriber.