Class Publisher<T>
- java.lang.Object
-
- io.servicetalk.concurrent.api.Publisher<T>
-
- Type Parameters:
T
- Type of items emitted.
- Direct Known Subclasses:
GroupedPublisher
,SubscribablePublisher
,TestPublisher
public abstract class Publisher<T> extends java.lang.Object
An asynchronous computation that produces 0, 1 or more elements and may or may not terminate successfully or with an error.How to subscribe?
This class does not provide a way to subscribe using aPublisherSource.Subscriber
as such calls are ambiguous about the intent whether the subscribe is part of the same source (a.k.a an operator) or it is a terminal subscribe. If it is required to subscribe to a source, then asource adapter
can be used to convert to aPublisherSource
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Publisher()
New instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Publisher<T>
afterCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.Publisher<T>
afterFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onafterFinally
TerminalSignalConsumer
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterFinally(java.lang.Runnable doFinally)
Invokes theafterFinally
Runnable
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument afterPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument afterPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterOnNext(java.util.function.Consumer<? super T> onNext)
Invokes theonNext
Consumer
argument afterPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterOnSubscribe(java.util.function.Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes theonSubscribe
Consumer
argument afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterRequest(java.util.function.LongConsumer onRequest)
Invokes theonRequest
LongConsumer
argument afterPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.Publisher<T>
afterSubscriber(java.util.function.Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscriber
methods after thePublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
afterSubscription(java.util.function.Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods after thePublisherSource.Subscription
s of the returnedPublisher
.Publisher<T>
beforeCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.Publisher<T>
beforeFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onbeforeFinally
TerminalSignalConsumer
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeFinally(java.lang.Runnable doFinally)
Invokes thebeforeFinally
Runnable
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument beforePublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeOnNext(java.util.function.Consumer<? super T> onNext)
Invokes theonNext
Consumer
argument beforePublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeOnSubscribe(java.util.function.Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes theonSubscribe
Consumer
argument beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeRequest(java.util.function.LongConsumer onRequest)
Invokes theonRequest
LongConsumer
argument beforePublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.Publisher<T>
beforeSubscriber(java.util.function.Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscriber
methods before thePublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
beforeSubscription(java.util.function.Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscription
methods before thePublisherSource.Subscription
s of the returnedPublisher
.<BC extends BufferStrategy.Accumulator<T,B>,B>
Publisher<B>buffer(BufferStrategy<T,BC,B> strategy)
<R> Single<R>
collect(java.util.function.Supplier<? extends R> resultFactory, java.util.function.BiFunction<? super R,? super T,R> collector)
Collects all items emitted by thisPublisher
into a single item.Completable
completableOrError()
Converts thisPublisher
to aCompletable
.Publisher<T>
concat(Completable next)
Publisher<T>
concat(Publisher<? extends T> next)
Publisher<T>
concat(Single<? extends T> next)
static <T> Publisher<T>
defer(java.util.function.Supplier<? extends Publisher<? extends T>> publisherSupplier)
Defers creation of aPublisher
till it is subscribed.static <T> Publisher<T>
empty()
Creates a newPublisher
that completes when subscribed without emitting any item to itsPublisherSource.Subscriber
.static <T> Publisher<T>
failed(java.lang.Throwable cause)
Creates a newPublisher
that terminates itsPublisherSource.Subscriber
with an error without emitting any item to it.Publisher<T>
filter(java.util.function.Predicate<? super T> predicate)
Filters items emitted by thisPublisher
.Single<T>
firstOrElse(java.util.function.Supplier<T> defaultValueSupplier)
Single<T>
firstOrError()
Ensures that thisPublisher
emits exactly a singlePublisherSource.Subscriber.onNext(Object)
to itsPublisherSource.Subscriber
.Completable
flatMapCompletable(java.util.function.Function<? super T,? extends Completable> mapper)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.Completable
flatMapCompletable(java.util.function.Function<? super T,? extends Completable> mapper, int maxConcurrency)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.Completable
flatMapCompletableDelayError(java.util.function.Function<? super T,? extends Completable> mapper)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.Completable
flatMapCompletableDelayError(java.util.function.Function<? super T,? extends Completable> mapper, int maxConcurrency)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.Completable
flatMapCompletableDelayError(java.util.function.Function<? super T,? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.<R> Publisher<R>
flatMapConcatIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
<R> Publisher<R>
flatMapMerge(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper)
<R> Publisher<R>
flatMapMerge(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency)
<R> Publisher<R>
flatMapMergeDelayError(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper)
<R> Publisher<R>
flatMapMergeDelayError(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency)
<R> Publisher<R>
flatMapMergeDelayError(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint)
<R> Publisher<R>
flatMapMergeSingle(java.util.function.Function<? super T,? extends Single<? extends R>> mapper)
<R> Publisher<R>
flatMapMergeSingle(java.util.function.Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency)
<R> Publisher<R>
flatMapMergeSingleDelayError(java.util.function.Function<? super T,? extends Single<? extends R>> mapper)
<R> Publisher<R>
flatMapMergeSingleDelayError(java.util.function.Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency)
<R> Publisher<R>
flatMapMergeSingleDelayError(java.util.function.Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Cancellable
forEach(java.util.function.Consumer<? super T> forEach)
static <T> Publisher<T>
from(T value)
Creates a newPublisher
that emitsvalue
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
from(T... values)
Creates a newPublisher
that emits allvalues
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
fromBlockingIterable(BlockingIterable<? extends T> iterable, java.util.function.LongSupplier timeoutSupplier, java.util.concurrent.TimeUnit unit)
Create a newPublisher
that when subscribed will get aBlockingIterator
viaBlockingIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static Publisher<byte[]>
fromInputStream(java.io.InputStream stream)
Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static Publisher<byte[]>
fromInputStream(java.io.InputStream stream, int readChunkSize)
Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.static <T> Publisher<T>
fromIterable(java.lang.Iterable<? extends T> iterable)
Create a newPublisher
that when subscribed will get anIterator
viaIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.<Key> Publisher<GroupedPublisher<Key,T>>
groupBy(java.util.function.Function<? super T,? extends Key> keySelector, int groupMaxQueueSize)
Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s.<Key> Publisher<GroupedPublisher<Key,T>>
groupBy(java.util.function.Function<? super T,? extends Key> keySelector, int groupMaxQueueSize, int expectedGroupCountHint)
Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s.<Key> Publisher<GroupedPublisher<Key,T>>
groupToMany(java.util.function.Function<? super T,? extends java.util.Iterator<? extends Key>> keySelector, int groupMaxQueueSize)
The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.<Key> Publisher<GroupedPublisher<Key,T>>
groupToMany(java.util.function.Function<? super T,? extends java.util.Iterator<? extends Key>> keySelector, int groupMaxQueueSize, int expectedGroupCountHint)
The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.protected abstract void
handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Handles a subscriber to thisPublisher
.Publisher<T>
idleTimeout(long duration, java.util.concurrent.TimeUnit unit)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Publisher<T>
idleTimeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Publisher<T>
idleTimeout(java.time.Duration duration)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Publisher<T>
idleTimeout(java.time.Duration duration, Executor timeoutExecutor)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls.Completable
ignoreElements()
Ignores all elements emitted by thisPublisher
and forwards the termination signal to the returnedCompletable
.<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(java.util.function.Function<? super T,? extends R> mapper)
Transforms elements emitted by thisPublisher
into a different type.Publisher<T>
multicastToExactly(int expectedSubscribers)
Create aPublisher
that multicasts all the signals to exactlyexpectedSubscribers
.Publisher<T>
multicastToExactly(int expectedSubscribers, int maxQueueSize)
Create aPublisher
that allows exactlyexpectedSubscribers
subscribes.static <T> Publisher<T>
never()
Creates a newPublisher
that never emits any item to itsPublisherSource.Subscriber
and never call any terminal methods on it.Publisher<T>
publishAndSubscribeOn(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods: AllPublisherSource.Subscriber
methods. AllPublisherSource.Subscription
methods. ThehandleSubscribe(PublisherSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
.Publisher<T>
publishAndSubscribeOnOverride(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods: AllPublisherSource.Subscriber
methods. AllPublisherSource.Subscription
methods. ThehandleSubscribe(PublisherSource.Subscriber)
method. This method overrides precedingExecutor
s, if any, specified forthis
Publisher
.Publisher<T>
publishOn(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods.Publisher<T>
publishOnOverride(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods.static Publisher<java.lang.Integer>
range(int begin, int end)
Create a newPublisher
that when subscribed will emit allInteger
s within the range of [begin
,end
).static Publisher<java.lang.Integer>
range(int begin, int end, int stride)
Create a newPublisher
that when subscribed will emit allInteger
s within the range of [begin
,end
) with an increment ofstride
between each signal.Publisher<T>
recoverWith(java.util.function.Function<java.lang.Throwable,? extends Publisher<? extends T>> nextFactory)
Publisher<T>
repeat(java.util.function.IntPredicate shouldRepeat)
Publisher<T>
repeatWhen(java.util.function.IntFunction<? extends Completable> repeatWhen)
Re-subscribes to thisPublisher
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully.Publisher<T>
retry(BiIntPredicate<java.lang.Throwable> shouldRetry)
Publisher<T>
retryWhen(BiIntFunction<java.lang.Throwable,? extends Completable> retryWhen)
Re-subscribes to thisPublisher
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully.<R> Publisher<R>
scanWith(java.util.function.Supplier<? extends ScanWithMapper<? super T,? extends R>> mapperSupplier)
Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream.<R> Publisher<R>
scanWith(java.util.function.Supplier<R> initial, java.util.function.BiFunction<R,? super T,R> accumulator)
Apply aBiFunction
to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
and an accumulated state.protected void
subscribeInternal(PublisherSource.Subscriber<? super T> subscriber)
A internal subscribe method similar toPublisherSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.Publisher<T>
subscribeOn(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods: AllPublisherSource.Subscription
methods. ThehandleSubscribe(PublisherSource.Subscriber)
method. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
.Publisher<T>
subscribeOnOverride(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods: AllPublisherSource.Subscription
methods. ThehandleSubscribe(PublisherSource.Subscriber)
method. This method overrides precedingExecutor
s, if any, specified forthis
Publisher
.Publisher<T>
subscribeShareContext()
Signifies that when the returnedPublisher
is subscribed to, theAsyncContext
will be shared instead of making acopy
.Publisher<T>
takeAtMost(long numElements)
Publisher<T>
takeUntil(Completable until)
Takes elements untilCompletable
is terminated successfully or with failure.Publisher<T>
takeWhile(java.util.function.Predicate<? super T> predicate)
Takes elements whilePredicate
istrue
and then cancelPublisherSource.Subscription
of thisPublisher
once it returnsfalse
.java.util.concurrent.CompletionStage<java.util.Collection<T>>
toCompletionStage()
<R> java.util.concurrent.CompletionStage<R>
toCompletionStage(java.util.function.Supplier<? extends R> resultFactory, java.util.function.BiFunction<? super R,? super T,R> reducer)
java.util.concurrent.Future<java.util.Collection<T>>
toFuture()
<R> java.util.concurrent.Future<R>
toFuture(java.util.function.Supplier<? extends R> resultFactory, java.util.function.BiFunction<? super R,? super T,R> reducer)
java.io.InputStream
toInputStream(java.util.function.Function<? super T,byte[]> serializer)
Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.java.io.InputStream
toInputStream(java.util.function.Function<? super T,byte[]> serializer, int queueCapacity)
Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.BlockingIterable<T>
toIterable()
BlockingIterable<T>
toIterable(int queueCapacityHint)
Publisher<T>
whenCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedPublisher
.Publisher<T>
whenFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onwhenFinally
TerminalSignalConsumer
argument when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenFinally(java.lang.Runnable doFinally)
Invokes thewhenFinally
Runnable
argument exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
forPublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument whenPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument whenPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenOnNext(java.util.function.Consumer<? super T> onNext)
Invokes theonNext
Consumer
argument whenPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenOnSubscribe(java.util.function.Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes theonSubscribe
Consumer
argument whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenRequest(java.util.function.LongConsumer onRequest)
Invokes theonRequest
LongConsumer
argument whenPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.Publisher<T>
whenSubscriber(java.util.function.Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes methods on thatPublisherSource.Subscriber
when the corresponding methods are called forPublisherSource.Subscriber
s of the returnedPublisher
.Publisher<T>
whenSubscription(java.util.function.Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods when the corresponding methods are called forPublisherSource.Subscription
s of the returnedPublisher
.
-
-
-
Method Detail
-
map
public final <R> Publisher<R> map(java.util.function.Function<? super T,? extends R> mapper)
Transforms elements emitted by thisPublisher
into a different type.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { results.add(mapper.apply(t)); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
mapper
- Function to transform each item emitted by thisPublisher
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
- ReactiveX map operator.
-
filter
public final Publisher<T> filter(java.util.function.Predicate<? super T> predicate)
Filters items emitted by thisPublisher
.This method provides a data transformation in sequential programming similar to:
List<T> results = ...; for (T t : resultOfThisPublisher()) { if (predicate.test(t)) { results.add(t); } } return results;
- Parameters:
predicate
- for the filter.- Returns:
- A
Publisher
that only emits the items that pass thepredicate
. - See Also:
- ReactiveX filter operator.
-
scanWith
public final <R> Publisher<R> scanWith(java.util.function.Supplier<R> initial, java.util.function.BiFunction<R,? super T,R> accumulator)
Apply aBiFunction
to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
and an accumulated state.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; R state = initial.get(); for (T t : resultOfThisPublisher()) { state = accumulator.apply(state, t); results.add(state); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
initial
- Invoked on eachPublisherSource.subscribe(Subscriber)
and provides the initial state for eachPublisherSource.Subscriber
.accumulator
- Used to accumulate the current state in combination with eachPublisherSource.Subscriber.onNext(Object)
from thisPublisher
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
- ReactiveX scan operator.
-
scanWith
public final <R> Publisher<R> scanWith(java.util.function.Supplier<? extends ScanWithMapper<? super T,? extends R>> mapperSupplier)
Apply a function to eachPublisherSource.Subscriber.onNext(Object)
emitted by thisPublisher
as well as optionally concat onePublisherSource.Subscriber.onNext(Object)
signal before the terminal signal is emitted downstream.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithMapper<T, R> mapper = mapperSupplier.get(); try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { if (mapTerminal.test(state)) { results.add(mapper.mapOnError(cause)); return; } throw cause; } if (mapTerminal.test(state)) { results.add(mapper.mapOnComplete()); } return results;
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
mapperSupplier
- Invoked on eachPublisherSource.subscribe(Subscriber)
and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber
.- Returns:
- A
Publisher
that transforms elements emitted by thisPublisher
into a different type. - See Also:
- ReactiveX scan operator.
-
recoverWith
public final Publisher<T> recoverWith(java.util.function.Function<java.lang.Throwable,? extends Publisher<? extends T>> nextFactory)
Recover from any error emitted by thisPublisher
by using anotherPublisher
provided by the passednextFactory
.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } return results;
- Parameters:
nextFactory
- Returns the nextPublisher
, when thisPublisher
emits an error.- Returns:
- A
Publisher
that recovers from an error from thisPublisher
by using anotherPublisher
provided by the passednextFactory
. - See Also:
- ReactiveX catch operator.
-
flatMapMerge
public final <R> Publisher<R> flatMapMerge(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper)
Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.To control the amount of concurrent processing done by this operator see
flatMapMerge(Function, int)
.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results;
-
flatMapMerge
public final <R> Publisher<R> flatMapMerge(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency)
Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results;
- Type Parameters:
R
- The type of mappedPublisher
.- Parameters:
mapper
- Convert each item emitted by thisPublisher
into anotherPublisher
.maxConcurrency
- Maximum amount of outstanding upstreamdemand
.- Returns:
- A new
Publisher
which flattens the emissions from all mappedPublisher
s. - See Also:
- ReactiveX flatMap operator.
-
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper)
Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This is the same as
flatMapMerge(Function)
just that if any mappedPublisher
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedPublisher
s to terminate and then terminate the returnedPublisher
with all errors emitted by the mappedPublisher
s.To control the amount of concurrent processing done by this operator see
flatMapMergeDelayError(Function, int)
.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);
-
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency)
Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This is the same as
flatMapMerge(Function)
just that if any mappedPublisher
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedPublisher
s to terminate and then terminate the returnedPublisher
with all errors emitted by the mappedPublisher
s.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);
- Type Parameters:
R
- The type of mappedPublisher
.- Parameters:
mapper
- Convert each item emitted by thisPublisher
into anotherPublisher
.maxConcurrency
- Maximum amount of outstanding upstreamdemand
.- Returns:
- A new
Publisher
which flattens the emissions from all mappedPublisher
s. - See Also:
- ReactiveX flatMap operator.
-
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(java.util.function.Function<? super T,? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Map each element of thisPublisher
into aPublisher
<Publisher
> and flatten all signals emitted from each mappedPublisher
<Publisher
> into the returnedPublisher
<Publisher
>.This is the same as
flatMapMerge(Function)
just that if any mappedPublisher
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedPublisher
s to terminate and then terminate the returnedPublisher
with all errors emitted by the mappedPublisher
s.This method is similar to
map(Function)
but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors);
- Type Parameters:
R
- The type of mappedPublisher
.- Parameters:
mapper
- Convert each item emitted by thisPublisher
into anotherPublisher
.maxConcurrency
- Maximum amount of outstanding upstreamdemand
.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A new
Publisher
which flattens the emissions from all mappedPublisher
s. - See Also:
- ReactiveX flatMap operator.
-
flatMapMergeSingle
public final <R> Publisher<R> flatMapMergeSingle(java.util.function.Function<? super T,? extends Single<? extends R>> mapper)
Map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.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;
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
- ReactiveX flatMap operator.,
flatMapMergeSingle(Function, int)
-
flatMapMergeSingle
public final <R> Publisher<R> flatMapMergeSingle(java.util.function.Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency)
Map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.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;
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
- ReactiveX flatMap operator.
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(java.util.function.Function<? super T,? extends Single<? extends R>> mapper)
Map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.The behavior is the same as
flatMapMergeSingle(Function, int)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and allSingle
s to terminate and then terminate the returnedPublisher
with all errors emitted by theSingle
s produced by themapper
.To control the amount of concurrent processing done by this operator see
flatMapMergeSingleDelayError(Function, int)
.This method is similar to
map(Function)
but the result is asynchronous, 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);
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
- ReactiveX merge operator.,
flatMapMergeSingleDelayError(Function, int)
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(java.util.function.Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency)
Map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.The behavior is the same as
flatMapMergeSingle(Function, int)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and allSingle
s to terminate and then terminate the returnedPublisher
with all errors emitted by theSingle
s produced by themapper
.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);
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
- ReactiveX merge operator.
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(java.util.function.Function<? super T,? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Map each element of thisPublisher
into aSingle
<Publisher
> and flatten all signals emitted from each mappedSingle
<Publisher
> into the returnedPublisher
<Publisher
>.The behavior is the same as
flatMapMergeSingle(Function, int)
with the exception that if anySingle
returned bymapper
, terminates with an error, the returnedPublisher
will not immediately terminate. Instead, it will wait for thisPublisher
and allSingle
s to terminate and then terminate the returnedPublisher
with all errors emitted by theSingle
s produced by themapper
.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);
- Type Parameters:
R
- Type of items emitted by the returnedPublisher
.- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aSingle
.maxConcurrency
- Maximum activeSingle
s at any time. Even if the number of items requested by aPublisherSource.Subscriber
is more than this number, this will never request more than this number at any point.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A new
Publisher
that emits all items emitted by each single produced bymapper
. - See Also:
- ReactiveX merge operator.
-
flatMapCompletable
public final Completable flatMapCompletable(java.util.function.Function<? super T,? extends Completable> mapper)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If the returned
Completable
should wait for the termination of all mappedCompletable
s when any one of them terminates with a failure,flatMapCompletableDelayError(Function)
should be used.To control the amount of concurrent processing done by this operator see
flatMapCompletable(Function, int)
.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<Void>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. }
- Parameters:
mapper
-Function
to convert each item emitted by thisPublisher
into aCompletable
.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
- ReactiveX flatMap operator.,
flatMapCompletable(Function, int)
,flatMapCompletableDelayError(Function)
-
flatMapCompletable
public final Completable flatMapCompletable(java.util.function.Function<? super T,? extends Completable> mapper, int maxConcurrency)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If the returned
Completable
should wait for the termination of all mappedCompletable
s when any one of them terminates with a failure,flatMapCompletableDelayError(Function)
should be used.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<Void>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. }
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.maxConcurrency
- Maximum activeCompletable
s at any time.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
- ReactiveX flatMap operator.,
flatMapCompletable(Function)
,flatMapCompletableDelayError(Function, int)
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(java.util.function.Function<? super T,? extends Completable> mapper)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If any mapped
Completable
terminates with an error the returnedCompletable
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedCompletable
s to terminate.To control the amount of concurrent processing done by this operator see
flatMapCompletableDelayError(Function, int)
.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to: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); }
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
- ReactiveX merge operator.,
flatMapMergeSingleDelayError(Function, int)
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(java.util.function.Function<? super T,? extends Completable> mapper, int maxConcurrency)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If any mapped
Completable
terminates with an error the returnedCompletable
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedCompletable
s to terminate.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to: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); }
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.maxConcurrency
- Maximum activeCompletable
s at any time.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
- ReactiveX merge operator.,
flatMapMergeSingleDelayError(Function, int)
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(java.util.function.Function<? super T,? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint)
Map each element of thisPublisher
into aCompletable
and flatten all signals such that the returnedCompletable
terminates when all mappedCompletable
s have terminated successfully or any one of them has terminated with a failure.If any mapped
Completable
terminates with an error the returnedCompletable
will not immediately terminate. Instead, it will wait for thisPublisher
and all mappedCompletable
s to terminate.This method is similar to
map(Function)
but the result is asynchronous, and provides a data transformation in sequential programming similar to: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); }
- Parameters:
mapper
- Function to convert each item emitted by thisPublisher
into aCompletable
.maxConcurrency
- Maximum activeCompletable
s at any time.maxDelayedErrorsHint
- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A new
Completable
that terminates successfully if all the intermediateCompletable
s have terminated successfully or any one of them has terminated with a failure. - See Also:
- ReactiveX merge operator.,
flatMapMergeSingleDelayError(Function, int)
-
flatMapConcatIterable
public final <R> Publisher<R> flatMapConcatIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
Create aPublisher
that flattens each element returned by theIterable.iterator()
frommapper
.The mapper
Function
will only be called when the previously returnedIterator
has returnedfalse
fromIterator.hasNext()
.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<R> results = ...; for (T t : resultOfThisPublisher()) { Iterable<? extends R> itr = mapper.apply(t); itr.forEach(results::add); } return results;
- Type Parameters:
R
- The elements returned by theIterable
.- Parameters:
mapper
- AFunction
that returns anIterable
for each element.- Returns:
- a
Publisher
that flattens each element returned by theIterable.iterator()
frommapper
. The results will be sequential for eachIterator
, and overall for all calls toIterable.iterator()
-
whenOnSubscribe
public final Publisher<T> whenOnSubscribe(java.util.function.Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes theonSubscribe
Consumer
argument whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onSubscribe
will be invoked relative toPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is undefined. If you need strict ordering seebeforeOnSubscribe(Consumer)
andafterOnSubscribe(Consumer)
.- Parameters:
onSubscribe
- Invoked whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
beforeOnNext(Consumer)
,afterOnNext(Consumer)
-
whenOnNext
public final Publisher<T> whenOnNext(java.util.function.Consumer<? super T> onNext)
Invokes theonNext
Consumer
argument whenPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onNext
will be invoked relative toPublisherSource.Subscriber.onNext(Object)
is undefined. If you need strict ordering seebeforeOnNext(Consumer)
andafterOnNext(Consumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
for (T t: resultOfThisPublisher()) { // NOTE: The order of operations here is not guaranteed by this method! processNext(t); onNext.accept(t); }
- Parameters:
onNext
- Invoked whenPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
beforeOnNext(Consumer)
,afterOnNext(Consumer)
-
whenOnComplete
public final Publisher<T> whenOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument whenPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onComplete
will be invoked relative toPublisherSource.Subscriber.onComplete()
is undefined. If you need strict ordering seebeforeOnComplete(Runnable)
andafterOnComplete(Runnable)
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); // NOTE: The order of operations here is not guaranteed by this method! onSuccess.accept(results); nextOperation(results);
- Parameters:
onComplete
- Invoked whenPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
beforeOnComplete(Runnable)
,afterOnComplete(Runnable)
-
whenOnError
public final Publisher<T> whenOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument whenPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.The order in which
onError
will be invoked relative toPublisherSource.Subscriber.onError(Throwable)
is undefined. If you need strict ordering seebeforeOnError(Consumer)
andafterOnError(Consumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch (Throwable cause) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(cause); onError.accept(cause); }
- Parameters:
onError
- Invoked beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
beforeOnError(Consumer)
,afterOnError(Consumer)
-
whenFinally
public final Publisher<T> whenFinally(java.lang.Runnable doFinally)
Invokes thewhenFinally
Runnable
argument exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.The order in which
whenFinally
will be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(Runnable)
andafterFinally(Runnable)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } finally { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.run(); }
- Parameters:
doFinally
- Invoked exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
beforeFinally(Runnable)
,afterFinally(Runnable)
-
whenFinally
public final Publisher<T> whenFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onwhenFinally
TerminalSignalConsumer
argument when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.The order in which
whenFinally
will be invoked relative to the above methods is undefined. If you need strict ordering seebeforeFinally(TerminalSignalConsumer)
andafterFinally(TerminalSignalConsumer)
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch(Throwable t) { // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } // NOTE: The order of operations here is not guaranteed by this method! nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();
- Parameters:
doFinally
- For each subscribe of the returnedPublisher
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Publisher
. - See Also:
beforeFinally(TerminalSignalConsumer)
,afterFinally(TerminalSignalConsumer)
-
whenRequest
public final Publisher<T> whenRequest(java.util.function.LongConsumer onRequest)
Invokes theonRequest
LongConsumer
argument whenPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onRequest
- Invoked whenPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
whenCancel
public final Publisher<T> whenCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument whenCancellable.cancel()
is called for Subscriptions of the returnedPublisher
.The order in which
whenFinally
will be invoked relative toCancellable.cancel()
is undefined. If you need strict ordering seebeforeCancel(Runnable)
andafterCancel(Runnable)
.- Parameters:
onCancel
- Invoked whenCancellable.cancel()
is called for Subscriptions of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
beforeCancel(Runnable)
,afterCancel(Runnable)
-
idleTimeout
public final Publisher<T> idleTimeout(long duration, java.util.concurrent.TimeUnit unit)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.unit
- The units forduration
.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
- ReactiveX timeout operator.,
idleTimeout(long, TimeUnit, io.servicetalk.concurrent.Executor)
-
idleTimeout
public final Publisher<T> idleTimeout(java.time.Duration duration)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
- ReactiveX timeout operator.,
idleTimeout(long, TimeUnit, io.servicetalk.concurrent.Executor)
-
idleTimeout
public final Publisher<T> idleTimeout(long duration, java.util.concurrent.TimeUnit unit, Executor timeoutExecutor)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.unit
- The units forduration
.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
- ReactiveX timeout operator.
-
idleTimeout
public final Publisher<T> idleTimeout(java.time.Duration duration, Executor timeoutExecutor)
Creates a newPublisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses between adjacentPublisherSource.Subscriber.onNext(Object)
calls. The timer starts when the returnedPublisher
is subscribed.In the event of timeout any
PublisherSource.Subscription
fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
will becancelled
and the associatedPublisherSource.Subscriber
will beterminated
.- Parameters:
duration
- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)
calls.timeoutExecutor
- TheExecutor
to use for managing the timer notifications.- Returns:
- a new
Publisher
that will mimic the signals of thisPublisher
but will terminate with aTimeoutException
if timeduration
elapses betweenPublisherSource.Subscriber.onNext(Object)
calls. - See Also:
- ReactiveX timeout operator.
-
concat
public final Publisher<T> concat(Publisher<? extends T> next)
Emits items emitted bynext
Publisher
afterthis
Publisher
terminates successfully.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); results.addAll(resultOfPublisher(next)); return results;
-
concat
public final Publisher<T> concat(Single<? extends T> next)
Listens and emits the result ofnext
Single
afterthis
Publisher
terminates successfully.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); results.add(resultOfSingle(next)); return results;
-
concat
public final Publisher<T> concat(Completable next)
Listens for completion ofnext
Completable
afterthis
Publisher
terminates successfully. Any error fromthis
Publisher
andnext
Completable
is forwarded to the returnedPublisher
.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); resultOfCompletable(next); return results;
- Parameters:
next
-Completable
to wait for completion afterthis
Publisher
terminates successfully.- Returns:
- A
Publisher
that emits all items from thisPublisher
and then awaits successful completion ofnext
Completable
. - See Also:
- ReactiveX concat operator.
-
retry
public final Publisher<T> retry(BiIntPredicate<java.lang.Throwable> shouldRetry)
Re-subscribes to thisPublisher
if an error is emitted and the passedBiIntPredicate
returnstrue
.This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:
public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1, results); } else { throw cause; } } }
- Parameters:
shouldRetry
-BiIntPredicate
that given the retry count and the most recentThrowable
emitted from thisPublisher
determines if the operation should be retried.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted if the passedBiIntPredicate
returnedtrue
. - See Also:
- ReactiveX retry operator.
-
retryWhen
public final Publisher<T> retryWhen(BiIntFunction<java.lang.Throwable,? extends Completable> retryWhen)
Re-subscribes to thisPublisher
if an error is emitted and theCompletable
returned by the suppliedBiIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedPublisher
terminates with that error.This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:
public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1, results); } catch (Throwable ignored) { throw cause; } } }
- Parameters:
retryWhen
-BiIntFunction
that given the retry count and the most recentThrowable
emitted from thisPublisher
returns aCompletable
. If thisCompletable
emits an error, that error is emitted from the returnedPublisher
, otherwise, originalPublisher
is re-subscribed when thisCompletable
completes.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted andCompletable
returned byBiIntFunction
completes successfully. - See Also:
- ReactiveX retry operator.
-
repeat
public final Publisher<T> repeat(java.util.function.IntPredicate shouldRepeat)
Re-subscribes to thisPublisher
when it completes and the passedIntPredicate
returnstrue
.This method provides a means to repeat an operation multiple times and in sequential programming is similar to:
List<T> results = new ...; int i = 0; do { results.addAll(resultOfThisPublisher()); } while (shouldRepeat.test(++i)); return results;
- Parameters:
shouldRepeat
-IntPredicate
that given the repeat count determines if the operation should be repeated.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes when it completes if the passedIntPredicate
returnstrue
. - See Also:
- ReactiveX repeat operator.
-
repeatWhen
public final Publisher<T> repeatWhen(java.util.function.IntFunction<? extends Completable> repeatWhen)
Re-subscribes to thisPublisher
when it completes and theCompletable
returned by the suppliedIntFunction
completes successfully. If the returnedCompletable
emits an error, the returnedPublisher
is completed.This method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:
List<T> results = new ...; int i = 0; while (true) { results.addAll(resultOfThisPublisher()); try { repeatWhen.apply(++i); // Either throws or completes normally } catch (Throwable cause) { break; } } return results;
- Parameters:
repeatWhen
-IntFunction
that given the repeat count returns aCompletable
. If thisCompletable
emits an error repeat is terminated, otherwise, originalPublisher
is re-subscribed when thisCompletable
completes.- Returns:
- A
Publisher
that emits all items from thisPublisher
and re-subscribes if an error is emitted andCompletable
returned byIntFunction
completes successfully. - See Also:
- ReactiveX retry operator.
-
takeAtMost
public final Publisher<T> takeAtMost(long numElements)
Takes at mostnumElements
elements fromthis
Publisher
.If no terminal event is received before receiving
numElements
elements,PublisherSource.Subscription
for thePublisherSource.Subscriber
is cancelled.This method provides a means to take a limited number of results from this
Publisher
and in sequential programming is similar to:List<T> results = ...; int i = 0; for (T t : resultOfThisPublisher()) { if (++i > numElements) { break; } results.add(t); } return results;
- Parameters:
numElements
- Number of elements to take.- Returns:
- A
Publisher
that emits at mostnumElements
elements fromthis
Publisher
. - See Also:
- ReactiveX take operator.
-
takeWhile
public final Publisher<T> takeWhile(java.util.function.Predicate<? super T> predicate)
Takes elements whilePredicate
istrue
and then cancelPublisherSource.Subscription
of thisPublisher
once it returnsfalse
.This method provides a means to take a limited number of results from this
Publisher
and in sequential programming is similar to:List<T> results = ...; for (T t : resultOfThisPublisher()) { if (!predicate.test(result)) { break; } results.add(t); } return results;
- Parameters:
predicate
-Predicate
that is checked before emitting any item to aPublisherSource.Subscriber
. If this predicate returnstrue
, that item is emitted, elsePublisherSource.Subscription
is cancelled.- Returns:
- A
Publisher
that only emits the items as long as thePredicate.test(Object)
method returnstrue
. - See Also:
- ReactiveX takeWhile operator.
-
takeUntil
public final Publisher<T> takeUntil(Completable until)
Takes elements untilCompletable
is terminated successfully or with failure.This method provides a means to take a limited number of results from this
Publisher
and in sequential programming is similar to:List<T> results = ...; for (T t : resultOfThisPublisher()) { if (isCompleted(until)) { break; } takeResults.add(t); } return results;
- Parameters:
until
-Completable
, termination of which, terminates the returnedPublisher
.- Returns:
- A
Publisher
that only emits the items tilluntil
Completable
is completed. - See Also:
- ReactiveX takeUntil operator.
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(java.util.function.Function<? super T,? extends Key> keySelector, int groupMaxQueueSize)
Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s. Item to group association is done bykeySelector
Function
. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriber
has not yet cancelled itsPublisherSource.Subscription
, this item is sent to thatPublisherSource.Subscriber
. Otherwise a newGroupedPublisher
is created and emitted from the returnedPublisher
.Flow control
MultiplePublisherSource.Subscriber
s (for multipleGroupedPublisher
s) request items individually from thisPublisher
. Since, there is no way for aPublisherSource.Subscriber
to only request elements for its group, elements requested by one group may end up producing items for a different group, which has not yet requested enough. This will cause items to be queued per group which can not be emitted due to lack of demand. This queue size can be controlled with themaxQueuePerGroup
argument.Cancellation
If thePublisherSource.Subscriber
of the returnedPublisher
cancels itsPublisherSource.Subscription
, then all activeGroupedPublisher
s will be terminated with an error and thePublisherSource.Subscription
to thisPublisher
will be cancelled.PublisherSource.Subscriber
s of individualGroupedPublisher
s can cancel theirPublisherSource.Subscription
s at any point. If any new item is emitted for the cancelledGroupedPublisher
, a newGroupedPublisher
will be emitted from the returnedPublisher
. Any queued items for a cancelledPublisherSource.Subscriber
for aGroupedPublisher
will be discarded and hence will not be emitted if the sameGroupedPublisher
is emitted again.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Key k = keySelector.apply(result); List<T> v = results.get(k); if (v == null) { v = // new List results.put(k, v); } v.add(result); } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to aGroupedPublisher
.groupMaxQueueSize
- Maximum number of new groups that will be queued due to thePublisherSource.Subscriber
of thePublisher
returned from this method not requesting enough viaPublisherSource.Subscription.request(long)
.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
- ReactiveX groupBy operator.
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(java.util.function.Function<? super T,? extends Key> keySelector, int groupMaxQueueSize, int expectedGroupCountHint)
Splits items from thisPublisher
into dynamically generatedGroupedPublisher
s. Item to group association is done bykeySelector
Function
. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriber
has not yet cancelled itsPublisherSource.Subscription
, this item is sent to thatPublisherSource.Subscriber
. Otherwise a newGroupedPublisher
is created and emitted from the returnedPublisher
.Flow control
MultiplePublisherSource.Subscriber
s (for multipleGroupedPublisher
s) request items individually from thisPublisher
. Since, there is no way for aPublisherSource.Subscriber
to only request elements for its group, elements requested by one group may end up producing items for a different group, which has not yet requested enough. This will cause items to be queued per group which can not be emitted due to lack of demand. This queue size can be controlled with themaxQueuePerGroup
argument.Cancellation
If thePublisherSource.Subscriber
of the returnedPublisher
cancels itsPublisherSource.Subscription
, then all activeGroupedPublisher
s will be terminated with an error and thePublisherSource.Subscription
to thisPublisher
will be cancelled.PublisherSource.Subscriber
s of individualGroupedPublisher
s can cancel theirPublisherSource.Subscription
s at any point. If any new item is emitted for the cancelledGroupedPublisher
, a newGroupedPublisher
will be emitted from the returnedPublisher
. Any queued items for a cancelledPublisherSource.Subscriber
for aGroupedPublisher
will be discarded and hence will not be emitted if the sameGroupedPublisher
is emitted again.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Key k = keySelector.apply(result); List<T> v = results.get(k); if (v == null) { v = // new List results.put(k, v); } v.add(result); } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to aGroupedPublisher
.groupMaxQueueSize
- Maximum number of new groups that will be queued due to thePublisherSource.Subscriber
of thePublisher
returned from this method not requesting enough viaPublisherSource.Subscription.request(long)
.expectedGroupCountHint
- Expected number of groups that would be emitted bythis
Publisher
. This is just a hint for internal data structures and does not have to be precise.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
- ReactiveX groupBy operator.
-
groupToMany
public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(java.util.function.Function<? super T,? extends java.util.Iterator<? extends Key>> keySelector, int groupMaxQueueSize)
The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Iterator<Key> keys = keySelector.apply(result); for (Key key : keys) { List<T> v = results.get(key); if (v == null) { v = // new List results.put(key, v); } v.add(result); } } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to multipleGroupedPublisher
s.groupMaxQueueSize
- Maximum number of new groups that will be queued due to thePublisherSource.Subscriber
of thePublisher
returned from this method not requesting enough viaPublisherSource.Subscription.request(long)
.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
groupBy(Function, int)
-
groupToMany
public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(java.util.function.Function<? super T,? extends java.util.Iterator<? extends Key>> keySelector, int groupMaxQueueSize, int expectedGroupCountHint)
The semantics are identical togroupBy(Function, int)
except that thekeySelector
can map each data to multiple keys.In sequential programming this is similar to the following:
Map<Key, List<T>> results = ...; for (T t : resultOfThisPublisher()) { Iterator<Key> keys = keySelector.apply(result); for (Key key : keys) { List<T> v = results.get(key); if (v == null) { v = // new List results.put(key, v); } v.add(result); } } return results;
- Type Parameters:
Key
- Type ofGroupedPublisher
keys.- Parameters:
keySelector
-Function
to assign an item emitted by thisPublisher
to multipleGroupedPublisher
s.groupMaxQueueSize
- Maximum number of new groups that will be queued due to thePublisherSource.Subscriber
of thePublisher
returned from this method not requesting enough viaPublisherSource.Subscription.request(long)
.expectedGroupCountHint
- Expected number of groups that would be emitted bythis
Publisher
. This is just a hint for internal data structures and does not have to be precise.- Returns:
- A
Publisher
that emitsGroupedPublisher
s for newkey
s as emitted bykeySelector
Function
. - See Also:
groupBy(Function, int)
-
multicastToExactly
public final Publisher<T> multicastToExactly(int expectedSubscribers)
Create aPublisher
that multicasts all the signals to exactlyexpectedSubscribers
.Depending on
PublisherSource.Subscription.request(long)
demand it is possible that data maybe queued before being delivered to eachPublisherSource.Subscriber
! For example if there are 2PublisherSource.Subscriber
s and the first callsrequest(10)
, and the second only callsrequest(1)
, then 9 elements will be queued to deliver to second when morePublisherSource.Subscription.request(long)
demand is made.In sequential programming this is similar to the following:
List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
-
multicastToExactly
public final Publisher<T> multicastToExactly(int expectedSubscribers, int maxQueueSize)
Create aPublisher
that allows exactlyexpectedSubscribers
subscribes. The events from thisPublisher
object will be delivered to eachPublisherSource.Subscriber
.Depending on
PublisherSource.Subscription.request(long)
demand it is possible that data maybe queued before being delivered to eachPublisherSource.Subscriber
! For example if there are 2PublisherSource.Subscriber
s and the first callsrequest(10)
, and the second only callsrequest(10)
, then 9 elements will be queued to deliver to second when morePublisherSource.Subscription.request(long)
demand is made.In sequential programming this is similar to the following:
List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;
- Parameters:
expectedSubscribers
- The number of expected subscribe calls required on the returnedPublisher
before subscribing to thisPublisher
.maxQueueSize
- The maximum number ofPublisherSource.Subscriber.onNext(Object)
events that will be queued if there is no demand for data before thePublisherSource.Subscriber
will be discarded.- Returns:
- a
Publisher
that allows exactlyexpectedSubscribers
subscribes.
-
buffer
public final <BC extends BufferStrategy.Accumulator<T,B>,B> Publisher<B> buffer(BufferStrategy<T,BC,B> strategy)
Create aPublisher
that buffers items from thisPublisher
and emit those buffers instead of the individual items.In sequential programming this is similar to the following:
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;
- Type Parameters:
BC
- Type of theBufferStrategy.Accumulator
to buffer items from thisPublisher
.B
- Type of the buffer emitted from the returnedPublisher
.- Parameters:
strategy
- ABufferStrategy
to use for buffering items from thisPublisher
.- Returns:
- a
Publisher
that buffers items from thisPublisher
and emit those buffers instead of the individual items. - See Also:
- ReactiveX buffer operator.
-
beforeOnSubscribe
public final Publisher<T> beforeOnSubscribe(java.util.function.Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes theonSubscribe
Consumer
argument beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
onSubscribe
- Invoked beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeOnNext
public final Publisher<T> beforeOnNext(java.util.function.Consumer<? super T> onNext)
Invokes theonNext
Consumer
argument beforePublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); for (T result : results) { onNext.accept(result); } nextOperation(results);
- Parameters:
onNext
- Invoked beforePublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeOnError
public final Publisher<T> beforeOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch (Throwable cause) { onError.accept(cause); nextOperation(cause); }
- Parameters:
onError
- Invoked beforePublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeOnComplete
public final Publisher<T> beforeOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument beforePublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); onComplete.run(); nextOperation(results);
- Parameters:
onComplete
- Invoked beforePublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeRequest
public final Publisher<T> beforeRequest(java.util.function.LongConsumer onRequest)
Invokes theonRequest
LongConsumer
argument beforePublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onRequest
- Invoked beforePublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeCancel
public final Publisher<T> beforeCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument beforeCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onCancel
- Invoked beforeCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeFinally
public final Publisher<T> beforeFinally(java.lang.Runnable doFinally)
Invokes thebeforeFinally
Runnable
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } finally { doFinally.run(); nextOperation(); // Maybe notifying of cancellation, or termination }
- Parameters:
doFinally
- Invoked before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeFinally
public final Publisher<T> beforeFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onbeforeFinally
TerminalSignalConsumer
argument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch(Throwable t) { doFinally.onError(t); nextOperation(); // Maybe notifying of cancellation, or termination return; } doFinally.onComplete(); nextOperation(); // Maybe notifying of cancellation, or termination
- Parameters:
doFinally
- For each subscribe of the returnedPublisher
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeSubscriber
public final Publisher<T> beforeSubscriber(java.util.function.Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscriber
methods before thePublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newPublisherSource.Subscriber
on each call to subscribe and invokes all thePublisherSource.Subscriber
methods before thePublisherSource.Subscriber
s of the returnedPublisher
.PublisherSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
beforeSubscription
public final Publisher<T> beforeSubscription(java.util.function.Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) on each call to subscribe and invokes all thePublisherSource.Subscription
methods before thePublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
subscriptionSupplier
- Creates a newPublisherSource.Subscription
on each call to subscribe and invokes all thePublisherSource.Subscription
methods before thePublisherSource.Subscription
s of the returnedPublisher
.PublisherSource.Subscription
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterOnSubscribe
public final Publisher<T> afterOnSubscribe(java.util.function.Consumer<? super PublisherSource.Subscription> onSubscribe)
Invokes theonSubscribe
Consumer
argument afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
onSubscribe
- Invoked afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterOnNext
public final Publisher<T> afterOnNext(java.util.function.Consumer<? super T> onNext)
Invokes theonNext
Consumer
argument afterPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); nextOperation(results); for (T result : results) { onNext.accept(result); }
- Parameters:
onNext
- Invoked afterPublisherSource.Subscriber.onNext(Object)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterOnError
public final Publisher<T> afterOnError(java.util.function.Consumer<java.lang.Throwable> onError)
Invokes theonError
Consumer
argument afterPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch (Throwable cause) { nextOperation(cause); onError.accept(cause); }
- Parameters:
onError
- Invoked afterPublisherSource.Subscriber.onError(Throwable)
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterOnComplete
public final Publisher<T> afterOnComplete(java.lang.Runnable onComplete)
Invokes theonComplete
Runnable
argument afterPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); nextOperation(results); onComplete.run();
- Parameters:
onComplete
- Invoked afterPublisherSource.Subscriber.onComplete()
is called forPublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterRequest
public final Publisher<T> afterRequest(java.util.function.LongConsumer onRequest)
Invokes theonRequest
LongConsumer
argument afterPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onRequest
- Invoked afterPublisherSource.Subscription.request(long)
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterCancel
public final Publisher<T> afterCancel(java.lang.Runnable onCancel)
Invokes theonCancel
Runnable
argument afterCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
onCancel
- Invoked afterCancellable.cancel()
is called forPublisherSource.Subscription
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterFinally
public final Publisher<T> afterFinally(java.lang.Runnable doFinally)
Invokes theafterFinally
Runnable
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } finally { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.run(); }
- Parameters:
doFinally
- Invoked after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
PublisherSource.Subscriber.onError(Throwable)
Cancellable.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
. MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterFinally
public final Publisher<T> afterFinally(TerminalSignalConsumer doFinally)
Invokes the corresponding method onafterFinally
TerminalSignalConsumer
argument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()
- invokesTerminalSignalConsumer.onComplete()
PublisherSource.Subscriber.onError(Throwable)
- invokesTerminalSignalConsumer.onError(Throwable)
Cancellable.cancel()
- invokesTerminalSignalConsumer.cancel()
PublisherSource.Subscription
s/PublisherSource.Subscriber
s of the returnedPublisher
.From a sequential programming point of view this method is roughly equivalent to the following:
try { List<T> results = resultOfThisPublisher(); } catch(Throwable t) { nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onError(t); return; } nextOperation(); // Maybe notifying of cancellation, or termination doFinally.onComplete();
- Parameters:
doFinally
- For each subscribe of the returnedPublisher
, at most one method of thisTerminalSignalConsumer
will be invoked.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
afterSubscriber
public final Publisher<T> afterSubscriber(java.util.function.Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscriber
methods after thePublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newPublisherSource.Subscriber
for each new subscribe and invokes all thePublisherSource.Subscriber
methods after thePublisherSource.Subscriber
s of the returnedPublisher
.PublisherSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
whenSubscriber
public final Publisher<T> whenSubscriber(java.util.function.Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier)
Creates a newPublisherSource.Subscriber
(via thesubscriberSupplier
argument) for each new subscribe and invokes methods on thatPublisherSource.Subscriber
when the corresponding methods are called forPublisherSource.Subscriber
s of the returnedPublisher
.- Parameters:
subscriberSupplier
- Creates a newPublisherSource.Subscriber
for each new subscribe and invokes methods on thatPublisherSource.Subscriber
when the corresponding methods are called forPublisherSource.Subscriber
s of the returnedPublisher
.PublisherSource.Subscriber
methods MUST NOT throw.- Returns:
- The new
Publisher
.
-
afterSubscription
public final Publisher<T> afterSubscription(java.util.function.Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods after thePublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
subscriptionSupplier
- Creates a newPublisherSource.Subscription
for each new subscribe and invokes all thePublisherSource.Subscription
methods after thePublisherSource.Subscription
s of the returnedPublisher
.PublisherSource.Subscription
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
whenSubscription
public final Publisher<T> whenSubscription(java.util.function.Supplier<? extends PublisherSource.Subscription> subscriptionSupplier)
Creates a newPublisherSource.Subscription
(via thesubscriptionSupplier
argument) for each new subscribe and invokes all thePublisherSource.Subscription
methods when the corresponding methods are called forPublisherSource.Subscription
s of the returnedPublisher
.- Parameters:
subscriptionSupplier
- Creates a newPublisherSource.Subscription
for each new subscribe and invokes all thePublisherSource.Subscription
methods when thePublisherSource.Subscription
s of the returnedPublisher
.PublisherSource.Subscription
methods MUST NOT throw.- Returns:
- The new
Publisher
. - See Also:
- ReactiveX do operator.
-
forEach
public final Cancellable forEach(java.util.function.Consumer<? super T> forEach)
Subscribes to thisPublisher
and invokesforEach
Consumer
for each item emitted by thisPublisher
.This will request
Long.MAX_VALUE
from thePublisherSource.Subscription
.From a sequential programming point of view this method is roughly equivalent to the following:
List<T> results = resultOfThisPublisher(); results.iterator().forEachRemaining(forEach);
- Parameters:
forEach
-Consumer
to invoke for eachPublisherSource.Subscriber.onNext(Object)
.- Returns:
Cancellable
used to invokeCancellable.cancel()
on the parameter ofPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
for thisPublisher
.
-
publishOn
public final Publisher<T> publishOn(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods. This method does not override precedingExecutor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
. If such an override is required,publishOnOverride(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke all methods ofPublisherSource.Subscriber
.
-
publishOnOverride
public final Publisher<T> publishOnOverride(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke allPublisherSource.Subscriber
methods. This method overrides precedingExecutor
s, if any, specified forthis
Publisher
. That is to say preceding and subsequent operations for this execution chain will use thisExecutor
. If such an override is not required,publishOn(Executor)
can be used.
-
subscribeOn
public final Publisher<T> subscribeOn(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods:- All
PublisherSource.Subscription
methods. - The
handleSubscribe(PublisherSource.Subscriber)
method.
Executor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
. If such an override is required,subscribeOnOverride(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke all methods ofPublisherSource.Subscription
andhandleSubscribe(PublisherSource.Subscriber)
.
- All
-
subscribeOnOverride
public final Publisher<T> subscribeOnOverride(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods:- All
PublisherSource.Subscription
methods. - The
handleSubscribe(PublisherSource.Subscriber)
method.
Executor
s, if any, specified forthis
Publisher
. That is to say preceding and subsequent operations for this execution chain will use thisExecutor
. If such an override is not required,subscribeOn(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke all methods ofPublisherSource.Subscription
andhandleSubscribe(PublisherSource.Subscriber)
both for the returnedPublisher
as well asthis
Publisher
.
- All
-
publishAndSubscribeOn
public final Publisher<T> publishAndSubscribeOn(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods:- All
PublisherSource.Subscriber
methods. - All
PublisherSource.Subscription
methods. - The
handleSubscribe(PublisherSource.Subscriber)
method.
Executor
s, if any, specified forthis
Publisher
. Only subsequent operations, if any, added in this execution chain will use thisExecutor
. If such an override is required,publishAndSubscribeOnOverride(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke all methodsPublisherSource.Subscriber
,PublisherSource.Subscription
andhandleSubscribe(PublisherSource.Subscriber)
.
- All
-
publishAndSubscribeOnOverride
public final Publisher<T> publishAndSubscribeOnOverride(Executor executor)
Creates a newPublisher
that will use the passedExecutor
to invoke the following methods:- All
PublisherSource.Subscriber
methods. - All
PublisherSource.Subscription
methods. - The
handleSubscribe(PublisherSource.Subscriber)
method.
Executor
s, if any, specified forthis
Publisher
. That is to say preceding and subsequent operations for this execution chain will use thisExecutor
. If such an override is not required,publishAndSubscribeOn(Executor)
can be used.- Parameters:
executor
-Executor
to use.- Returns:
- A new
Publisher
that will use the passedExecutor
to invoke all methods ofPublisherSource.Subscriber
,PublisherSource.Subscription
andhandleSubscribe(PublisherSource.Subscriber)
both for the returnedPublisher
as well asthis
Publisher
.
- All
-
subscribeShareContext
public final Publisher<T> subscribeShareContext()
Signifies that when the returnedPublisher
is subscribed to, theAsyncContext
will be shared instead of making acopy
.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.- Returns:
- A
Publisher
that will share theAsyncContext
instead of making acopy
when subscribed to.
-
liftSync
public final <R> Publisher<R> liftSync(PublisherOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Publisher
which when subscribed, theoperator
argument will be used to wrap thePublisherSource.Subscriber
before subscribing to thisPublisher
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .filter(..) // B
original -> modified
"operator" MUST be "synchronous" in that it does not interact with the originalPublisherSource.Subscriber
from outside the modifiedPublisherSource.Subscriber
orPublisherSource.Subscription
threads. That is to say this operator will not impact theExecutor
constraints already in place between A and B above. If you need asynchronous behavior, or are unsure, seeliftAsync(PublisherOperator)
.- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
operator
- The custom operator logic. The input is the "original"PublisherSource.Subscriber
to thisPublisher
and the return is the "modified"PublisherSource.Subscriber
that provides custom operator business logic.- Returns:
- a
Publisher
which when subscribed, theoperator
argument will be used to wrap thePublisherSource.Subscriber
before subscribing to thisPublisher
. - See Also:
liftAsync(PublisherOperator)
-
liftSyncToSingle
public final <R> Single<R> liftSyncToSingle(PublisherToSingleOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Single
which when subscribed, theoperator
argument will be used to convert between theSingleSource.Subscriber
to aPublisherSource.Subscriber
before subscribing to thisPublisher
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .filter(..) // B - we have converted to Single now!
original -> modified
"operator" MUST be "synchronous" in that it does not interact with the originalPublisherSource.Subscriber
from outside the modifiedPublisherSource.Subscriber
orPublisherSource.Subscription
threads. That is to say this operator will not impact theExecutor
constraints already in place between A and B above. If you need asynchronous behavior, or are unsure, don't use this operator.- Type Parameters:
R
- Type of the items emitted by the returnedSingle
.- Parameters:
operator
- The custom operator logic. The input is the "original"SingleSource.Subscriber
to the returnedSingle
and the return is the "modified"PublisherSource.Subscriber
that provides custom operator business logic on thisPublisher
.- Returns:
- a
Single
which when subscribed, theoperator
argument will be used to convert theSingleSource.Subscriber
to aPublisherSource.Subscriber
before subscribing to thisPublisher
.
-
liftAsync
public final <R> Publisher<R> liftAsync(PublisherOperator<? super T,? extends R> operator)
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Publisher
which will wrap thePublisherSource.Subscriber
using the providedoperator
argument before subscribing to thisPublisher
.
ThePublisher<X> pub = ...; pub.map(..) // A .liftAsync(original -> modified) .filter(..) // B
original -> modified
"operator" MAY be "asynchronous" in that it may interact with the originalPublisherSource.Subscriber
from outside the modifiedPublisherSource.Subscriber
orPublisherSource.Subscription
threads. More specifically:- all of the
PublisherSource.Subscriber
invocations going "downstream" (i.e. from A to B above) MAY be offloaded via anExecutor
- all of the
PublisherSource.Subscription
invocations going "upstream" (i.e. from B to A above) MAY be offloaded via anExecutor
- Type Parameters:
R
- Type of the items emitted by the returnedPublisher
.- Parameters:
operator
- The custom operator logic. The input is the "original"PublisherSource.Subscriber
to thisPublisher
and the return is the "modified"PublisherSource.Subscriber
that provides custom operator business logic.- Returns:
- a
Publisher
which when subscribed, theoperator
argument will be used to wrap thePublisherSource.Subscriber
before subscribing to thisPublisher
. - See Also:
liftSync(PublisherOperator)
- all of the
-
firstOrElse
public final Single<T> firstOrElse(java.util.function.Supplier<T> defaultValueSupplier)
- Parameters:
defaultValueSupplier
- ASupplier
of default value if thisPublisher
did not emit any item.- Returns:
- A
Single
that will contain the first item emitted from the thisPublisher
. If the sourcePublisher
does not emit any item, then the returnedSingle
will contain the value as returned by the passedSupplier
. - See Also:
- ReactiveX first operator.
-
firstOrError
public final Single<T> firstOrError()
Ensures that thisPublisher
emits exactly a singlePublisherSource.Subscriber.onNext(Object)
to itsPublisherSource.Subscriber
. If thisPublisher
terminates without emitting any items aNoSuchElementException
will be signaled and if thisPublisher
emits more than one item, anIllegalArgumentException
will be signaled. Any error emitted by thisPublisher
will be forwarded to the returnedSingle
.
-
ignoreElements
public final Completable ignoreElements()
Ignores all elements emitted by thisPublisher
and forwards the termination signal to the returnedCompletable
.- Returns:
- A
Completable
that mirrors the terminal signal from thisPublisher
. - See Also:
- ReactiveX ignoreElements operator.
-
completableOrError
public final Completable completableOrError()
Converts thisPublisher
to aCompletable
. If thisPublisher
emits anyPublisherSource.Subscriber.onNext(Object)
signals the resultingCompletable
will be terminated with aIllegalArgumentException
.- Returns:
- A
Completable
that mirrors the terminal signal from thisPublisher
, and terminates in error if anPublisherSource.Subscriber.onNext(Object)
signals.
-
collect
public final <R> Single<R> collect(java.util.function.Supplier<? extends R> resultFactory, java.util.function.BiFunction<? super R,? super T,R> collector)
Collects all items emitted by thisPublisher
into a single item.- Type Parameters:
R
- Type of the reduced item.- Parameters:
resultFactory
- Factory for the result which collects all items emitted by thisPublisher
. This will be called every time the returnedSingle
is subscribed.collector
- Invoked for every item emitted by the sourcePublisher
and returns the same or alteredresult
object.- Returns:
- A
Single
that completes with the singleresult
or any error emitted by the sourcePublisher
. - See Also:
- ReactiveX reduce operator.
-
toFuture
public final java.util.concurrent.Future<java.util.Collection<T>> toFuture()
Convert thisPublisher
into aFuture
with aCollection
containing the elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediateCollection
will be discarded and theFuture
will complete exceptionally.- Returns:
- a
Future
with aCollection
containing the elements of thisPublisher
upon successful termination. - See Also:
toFuture(Supplier, BiFunction)
-
toFuture
public final <R> java.util.concurrent.Future<R> toFuture(java.util.function.Supplier<? extends R> resultFactory, java.util.function.BiFunction<? super R,? super T,R> reducer)
Convert thisPublisher
into aFuture
of typePublisher
which represents all elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediatePublisher
will be discarded and theFuture
will complete exceptionally.- Type Parameters:
R
- Type of the reduced item.- Parameters:
resultFactory
- Factory for the result which collects all items emitted by thisPublisher
.reducer
- Invoked for every item emitted by the sourcePublisher
and returns the same or alteredresult
object.- Returns:
- a
Future
of typePublisher
which represents all elements of thisPublisher
upon successful termination.
-
toCompletionStage
public final java.util.concurrent.CompletionStage<java.util.Collection<T>> toCompletionStage()
Convert thisPublisher
into aCompletionStage
with aCollection
containing the elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediateCollection
will be discarded and theCompletionStage
will complete exceptionally.- Returns:
- a
CompletionStage
with aCollection
containing the elements of thisPublisher
upon successful termination. - See Also:
toCompletionStage(Supplier, BiFunction)
-
toCompletionStage
public final <R> java.util.concurrent.CompletionStage<R> toCompletionStage(java.util.function.Supplier<? extends R> resultFactory, java.util.function.BiFunction<? super R,? super T,R> reducer)
Convert thisPublisher
into aCompletionStage
of typePublisher
which represents all elements of thisPublisher
upon successful termination. If thisPublisher
terminates in an error, then the intermediatePublisher
will be discarded and theCompletionStage
will complete exceptionally.- Type Parameters:
R
- Type of the reduced item.- Parameters:
resultFactory
- Factory for the result which collects all items emitted by thisPublisher
.reducer
- Invoked for every item emitted by the sourcePublisher
and returns the same or alteredresult
object.- Returns:
- a
CompletionStage
of typePublisher
which represents all elements of thisPublisher
upon successful termination.
-
toInputStream
public final java.io.InputStream toInputStream(java.util.function.Function<? super T,byte[]> serializer)
Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required. If the returnedInputStream
is closed,PublisherSource.Subscription
is cancelled and any unread data is disposed.- Any items received by
PublisherSource.Subscriber.onNext(Object)
are converted to abyte[]
using the passedserializer
. Thesebyte
s are available to be read from theInputStream
- Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in anIOException
) when data is read from the returnedInputStream
. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedInputStream
's read methods will return-1
to indicate end of stream after emitting all received data.
Flow control
This operator may pre-fetch may pre-fetch items fromthis
Publisher
if available to reduce blocking for read operations from the returnedInputStream
. In order to increase responsiveness of theInputStream
some amount of buffering may be done. UsetoInputStream(Function, int)
to manage capacity of this buffer.- Parameters:
serializer
-Function
that is invoked for every item emitted bythis
Publisher
.- Returns:
InputStream
that emits all data emitted bythis
Publisher
. Ifthis
Publisher
terminates with an error, same error is thrown (wrapped in anIOException
) from the returnedInputStream
s read methods after emitting all received data.
-
toInputStream
public final java.io.InputStream toInputStream(java.util.function.Function<? super T,byte[]> serializer, int queueCapacity)
Subscribes tothis
Publisher
and converts all signals received by thePublisherSource.Subscriber
to the returnedInputStream
following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required. If the returnedInputStream
is closed,PublisherSource.Subscription
is cancelled and any unread data is disposed.- Any items received by
PublisherSource.Subscriber.onNext(Object)
are convertedto abyte[]
using the passedserializer
. Thesebyte
s are available to be read from theInputStream
- Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in anIOException
) when data is read from the returnedInputStream
. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedInputStream
's read methods will return-1
to indicate end of stream after emitting all received data.
Flow control
This operator may pre-fetch items fromthis
Publisher
if available to reduce blocking for read operations from the returnedInputStream
. In order to increase responsiveness of theInputStream
some amount of buffering may be done.queueCapacity
can be used to bound this buffer.- Parameters:
serializer
-Function
that is invoked for every item emitted bythis
Publisher
.queueCapacity
- Hint for the capacity of the intermediary queue that stores items that are emitted bythis
Publisher
but has not yet been read from the returnedInputStream
.- Returns:
InputStream
that emits all data emitted bythis
Publisher
. Ifthis
Publisher
terminates with an error, same error is thrown (wrapped in anIOException
) from the returnedInputStream
s read methods after emitting all received data.
-
toIterable
public final BlockingIterable<T> toIterable()
Convertsthis
Publisher
to anBlockingIterable
. Every timeBlockingIterable.iterator()
is called on the returnedBlockingIterable
,this
Publisher
is subscribed following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.- Any items received by
PublisherSource.Subscriber.onNext(Object)
is returned from a call toBlockingIterator.next()
. - Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in aRuntimeException
if required) whenBlockingIterator.next()
is called. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedBlockingIterator
sIterator.hasNext()
will returnfalse
BlockingIterator.next()
will throwNoSuchElementException
. This error will be thrown only after draining all queued data, if any.
Flow control
This operator may pre-fetch items fromthis
Publisher
if available to reduce blocking ofIterator.hasNext()
from the returnedBlockingIterable
. In order to increase responsiveness of theIterator
some amount of buffering may be done. UsetoIterable(int)
to manage capacity of this buffer.Blocking
The returnedBlockingIterator
from the returnedBlockingIterable
will block onIterator.hasNext()
andBlockingIterator.next()
if no data is available. This operator may try to reduce this blocking by requesting data ahead of time.- Returns:
BlockingIterable
representingthis
Publisher
. Every timeBlockingIterable.iterator()
is invoked on theBlockingIterable
,this
Publisher
is subscribed.BlockingIterator
s returned from thisBlockingIterable
do not supportIterator.remove()
.
-
toIterable
public final BlockingIterable<T> toIterable(int queueCapacityHint)
Convertsthis
Publisher
to anBlockingIterable
. Every timeBlockingIterable.iterator()
is called on the returnedBlockingIterable
,this
Publisher
is subscribed following the below rules:PublisherSource.Subscription
received byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
is used to request more data when required.- Any items received by
PublisherSource.Subscriber.onNext(Object)
is returned from a call toBlockingIterator.next()
. - Any
Throwable
received byPublisherSource.Subscriber.onError(Throwable)
is thrown (wrapped in aRuntimeException
if required) whenBlockingIterator.next()
. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()
is called, returnedBlockingIterator
sIterator.hasNext()
will returnfalse
andBlockingIterator.next()
will throwNoSuchElementException
. This error will be thrown only after draining all queued data, if any.
Flow control
This operator may pre-fetch items fromthis
Publisher
if available to reduce blocking ofIterator.hasNext()
from the returnedBlockingIterable
. In order to increase responsiveness of theBlockingIterator
some amount of buffering may be done.queueCapacityHint
can be used to bound this buffer.Blocking
The returnedBlockingIterator
from the returnedBlockingIterable
will block onIterator.hasNext()
andBlockingIterator.next()
if no data is available. This operator may try to reduce this blocking by requesting data ahead of time.- Parameters:
queueCapacityHint
- Hint for the capacity of the intermediary queue that stores items that are emitted bythis
Publisher
but has not yet been returned from theBlockingIterator
.- Returns:
BlockingIterable
representingthis
Publisher
. Every timeBlockingIterable.iterator()
is invoked on theBlockingIterable
,this
Publisher
is subscribed.BlockingIterator
s returned from thisBlockingIterable
do not supportIterator.remove()
.
-
subscribeInternal
protected final void subscribeInternal(PublisherSource.Subscriber<? super T> subscriber)
A internal subscribe method similar toPublisherSource.subscribe(Subscriber)
which can be used by different implementations to subscribe.- Parameters:
subscriber
-PublisherSource.Subscriber
to subscribe for the result.
-
handleSubscribe
protected abstract void handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Handles a subscriber to thisPublisher
.- Parameters:
subscriber
- the subscriber.
-
from
public static <T> Publisher<T> from(@Nullable T value)
Creates a newPublisher
that emitsvalue
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
value
- Value that the returnedPublisher
will emit.- Returns:
- A new
Publisher
that emitsvalue
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
. - See Also:
- ReactiveX just operator.
-
from
@SafeVarargs public static <T> Publisher<T> from(T... values)
Creates a newPublisher
that emits allvalues
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
values
- Values that the returnedPublisher
will emit.- Returns:
- A new
Publisher
that emits allvalues
to itsPublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
. - See Also:
- ReactiveX from operator.
-
fromIterable
public static <T> Publisher<T> fromIterable(java.lang.Iterable<? extends T> iterable)
Create a newPublisher
that when subscribed will get anIterator
viaIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of theiterable
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
iterable
- used to obtain instances ofIterator
to extract data from.Iterable.iterator()
must not returnnull
. If this is of typeBlockingIterable
then any generatedBlockingIterator
s will have theirBlockingIterator.close()
method called if an error occurs.- Returns:
- a new
Publisher
that when subscribed will get anIterator
viaIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromBlockingIterable
public static <T> Publisher<T> fromBlockingIterable(BlockingIterable<? extends T> iterable, java.util.function.LongSupplier timeoutSupplier, java.util.concurrent.TimeUnit unit)
Create a newPublisher
that when subscribed will get aBlockingIterator
viaBlockingIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of theiterable
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
iterable
- used to obtain instances ofIterator
to extract data from.Iterable.iterator()
must not returnnull
. Any generatedBlockingIterator
s will have theirBlockingIterator.close()
method called if an error occurs.timeoutSupplier
- ALongSupplier
which provides the time duration to wait for each interaction withiterable
.unit
- The time units for thetimeout
duration.- Returns:
- a new
Publisher
that when subscribed will get aBlockingIterator
viaBlockingIterable.iterator()
and emit all values to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromInputStream
public static Publisher<byte[]> fromInputStream(java.io.InputStream stream)
Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of thestream
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Parameters:
stream
- provides the data in the form ofbyte[]
to be emitted to thePublisherSource.Subscriber
by the returnedPublisher
. Given the blocking nature ofInputStream
, assumePublisherSource.Subscription.request(long)
can block when the underlyingInputStream
blocks onInputStream.read(byte[], int, int)
.- Returns:
- a new
Publisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
fromInputStream
public static Publisher<byte[]> fromInputStream(java.io.InputStream stream, int readChunkSize)
Create a newPublisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscription
should be "responsive". The responsiveness of the associatedPublisherSource.Subscription
s will depend upon the behavior of thestream
below. Make sure theExecutor
for this execution chain can tolerate this responsiveness and any blocking behavior.- Parameters:
stream
- provides the data in the form ofbyte[]
to be emitted to thePublisherSource.Subscriber
by the returnedPublisher
. Given the blocking nature ofInputStream
, assumePublisherSource.Subscription.request(long)
can block when the underlyingInputStream
blocks onInputStream.read(byte[], int, int)
.readChunkSize
- the maximum length ofbyte[]
chunks which will be read from theInputStream
and emitted by the returnedPublisher
.- Returns:
- a new
Publisher
that when subscribed will emit all data from theInputStream
to thePublisherSource.Subscriber
and thenPublisherSource.Subscriber.onComplete()
.
-
range
public static Publisher<java.lang.Integer> range(int begin, int end)
Create a newPublisher
that when subscribed will emit allInteger
s within the range of [begin
,end
).
-
range
public static Publisher<java.lang.Integer> range(int begin, int end, int stride)
Create a newPublisher
that when subscribed will emit allInteger
s within the range of [begin
,end
) with an increment ofstride
between each signal.- Parameters:
begin
- The beginning of the range (inclusive).end
- The end of the range (exclusive).stride
- The amount to increment in between each signal.- Returns:
- a new
Publisher
that when subscribed will emit allInteger
s within the range of [begin
,end
) with an increment ofstride
between each signal. - See Also:
- Range.
-
empty
public static <T> Publisher<T> empty()
Creates a newPublisher
that completes when subscribed without emitting any item to itsPublisherSource.Subscriber
.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Returns:
- A new
Publisher
that completes when subscribed without emitting any item to itsPublisherSource.Subscriber
. - See Also:
- ReactiveX empty operator.
-
never
public static <T> Publisher<T> never()
Creates a newPublisher
that never emits any item to itsPublisherSource.Subscriber
and never call any terminal methods on it.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Returns:
- A new
Publisher
that never emits any item to itsPublisherSource.Subscriber
and never call any terminal methods on it. - See Also:
- ReactiveX never operator.
-
failed
public static <T> Publisher<T> failed(java.lang.Throwable cause)
Creates a newPublisher
that terminates itsPublisherSource.Subscriber
with an error without emitting any item to it.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
cause
- TheThrowable
that is used to terminate thePublisherSource.Subscriber
.- Returns:
- A new
Publisher
that terminates itsPublisherSource.Subscriber
with an error without emitting any item to it. - See Also:
- ReactiveX error operator.
-
defer
public static <T> Publisher<T> defer(java.util.function.Supplier<? extends Publisher<? extends T>> publisherSupplier)
Defers creation of aPublisher
till it is subscribed.- Type Parameters:
T
- Type of items emitted by the returnedPublisher
.- Parameters:
publisherSupplier
-Supplier
to create a newPublisher
every time the returnedPublisher
is subscribed.- Returns:
- A new
Publisher
that creates a newPublisher
usingpublisherSupplier
every time it is subscribed and forwards all items and terminal events from the newly createdPublisher
to itsPublisherSource.Subscriber
. - See Also:
- ReactiveX defer operator.
-
-