Class Publisher<T>
- Type Parameters:
T- Type of items emitted.
- Direct Known Subclasses:
GroupedPublisher,SubscribablePublisher
How to subscribe?
This class does not provide a way to subscribe using aPublisherSource.Subscriber as such calls are
ambiguous about the intent whether the subscribe is part of the same source (a.k.a an operator) or it is a terminal
subscribe. If it is required to subscribe to a source, then a source adapter can be used to
convert to a PublisherSource.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionafterCancel(Runnable onCancel) Invokes theonCancelRunnableargument afterCancellable.cancel()is called forPublisherSource.Subscriptions of the returnedPublisher.afterFinally(TerminalSignalConsumer doFinally) Invokes the corresponding method onafterFinallyTerminalSignalConsumerargument 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.afterFinally(Runnable doFinally) Invokes theafterFinallyRunnableargument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()forPublisherSource.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.afterOnComplete(Runnable onComplete) Invokes theonCompleteRunnableargument afterPublisherSource.Subscriber.onComplete()is called forPublisherSource.Subscribers of the returnedPublisher.afterOnError(Consumer<Throwable> onError) Invokes theonErrorConsumerargument afterPublisherSource.Subscriber.onError(Throwable)is called forPublisherSource.Subscribers of the returnedPublisher.afterOnNext(Consumer<? super T> onNext) Invokes theonNextConsumerargument afterPublisherSource.Subscriber.onNext(Object)is called forPublisherSource.Subscribers of the returnedPublisher.afterOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribeConsumerargument afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher.afterRequest(LongConsumer onRequest) Invokes theonRequestLongConsumerargument afterPublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher.afterSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes all thePublisherSource.Subscribermethods after thePublisherSource.Subscribers of the returnedPublisher.afterSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription(via thesubscriptionSupplierargument) for each new subscribe and invokes all thePublisherSource.Subscriptionmethods after thePublisherSource.Subscriptions of the returnedPublisher.beforeCancel(Runnable onCancel) Invokes theonCancelRunnableargument beforeCancellable.cancel()is called forPublisherSource.Subscriptions of the returnedPublisher.beforeFinally(TerminalSignalConsumer doFinally) Invokes the corresponding method onbeforeFinallyTerminalSignalConsumerargument 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.beforeFinally(Runnable doFinally) Invokes thebeforeFinallyRunnableargument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()forPublisherSource.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.beforeOnComplete(Runnable onComplete) Invokes theonCompleteRunnableargument beforePublisherSource.Subscriber.onComplete()is called forPublisherSource.Subscribers of the returnedPublisher.beforeOnError(Consumer<Throwable> onError) Invokes theonErrorConsumerargument beforePublisherSource.Subscriber.onError(Throwable)is called forPublisherSource.Subscribers of the returnedPublisher.beforeOnNext(Consumer<? super T> onNext) Invokes theonNextConsumerargument beforePublisherSource.Subscriber.onNext(Object)is called forPublisherSource.Subscribers of the returnedPublisher.beforeOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribeConsumerargument beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher.beforeRequest(LongConsumer onRequest) Invokes theonRequestLongConsumerargument beforePublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher.beforeSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all thePublisherSource.Subscribermethods before thePublisherSource.Subscribers of the returnedPublisher.beforeSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription(via thesubscriptionSupplierargument) on each call to subscribe and invokes all thePublisherSource.Subscriptionmethods before thePublisherSource.Subscriptions of the returnedPublisher.final <BC extends BufferStrategy.Accumulator<T,B>, B>
Publisher<B>buffer(BufferStrategy<T, BC, B> strategy) final <R> Publisher<R>final <R> Single<R>collect(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> collector) Collects all items emitted by thisPublisherinto a single item.final CompletableConverts thisPublisherto aCompletable.concat(Completable next) This method is likeconcat(Completable)exceptnextwill be subscribed to and cancelled if thisPublisheris cancelled or terminates withPublisherSource.Subscriber.onError(Throwable).static <T> Publisher<T>Defers creation of aPublishertill it is subscribed.distinct()Only emits distinct signals observed by thisPublisher.static <T> Publisher<T>empty()Creates a newPublisherthat completes when subscribed without emitting any item to itsPublisherSource.Subscriber.static <T> Publisher<T>Creates a newPublisherthat terminates itsPublisherSource.Subscriberwith an error without emitting any item to it.Filters items emitted by thisPublisher.final <R> Single<R>firstAndTail(BiFunction<T, Publisher<T>, R> packer) firstOrElse(Supplier<T> defaultValueSupplier) final CompletableflatMapCompletable(Function<? super T, ? extends Completable> mapper) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.final CompletableflatMapCompletable(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.final CompletableflatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.final CompletableflatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.final CompletableflatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.final <R> Publisher<R>flatMapConcatIterable(Function<? super T, ? extends Iterable<? extends R>> mapper) final <R> Publisher<R>flatMapConcatSingle(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)but the result is asynchronous.final <R> Publisher<R>flatMapConcatSingle(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous.final <R> Publisher<R>flatMapConcatSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)but the result is asynchronous.final <R> Publisher<R>flatMapConcatSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous.final <R> Publisher<R>flatMapMerge(Function<? super T, ? extends Publisher<? extends R>> mapper) final <R> Publisher<R>flatMapMerge(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) final <R> Publisher<R>flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) final <R> Publisher<R>flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) final <R> Publisher<R>flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) final <R> Publisher<R>flatMapMergeSingle(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)but the result is asynchronous and results are unordered.final <R> Publisher<R>flatMapMergeSingle(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous and results are unordered.final <R> Publisher<R>flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper) final <R> Publisher<R>flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous and results are unordered.final <R> Publisher<R>flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) This method is similar tomap(Function)but the result is asynchronous and results are unordered.final Cancellablestatic <T> Publisher<T>from(T value) Creates a newPublisherthat emitsvalueto itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().static <T> Publisher<T>from(T... values) Creates a newPublisherthat emits allvaluesto itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().static <T> Publisher<T>from(T v1, T v2) Creates a newPublisherthat emitsv1andv2to itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().static <T> Publisher<T>from(T v1, T v2, T v3) Creates a newPublisherthat emitsv1,v2, andv3to itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().static <T> Publisher<T>fromBlockingIterable(BlockingIterable<? extends T> iterable, LongSupplier timeoutSupplier, TimeUnit unit) Create a newPublisherthat when subscribed will get aBlockingIteratorviaBlockingIterable.iterator()and emit all values to thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().static Publisher<byte[]>fromInputStream(InputStream stream) Deprecated.static Publisher<byte[]>fromInputStream(InputStream stream, int readChunkSize) Deprecated.static <T> Publisher<T>fromInputStream(InputStream stream, ByteArrayMapper<T> mapper) Create a newPublisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberas a mapped typeTand thenPublisherSource.Subscriber.onComplete().static <T> Publisher<T>fromIterable(Iterable<? extends T> iterable) Create a newPublisherthat when subscribed will get anIteratorviaIterable.iterator()and emit all values to thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().final <Key> Publisher<GroupedPublisher<Key,T>> Splits items from thisPublisherinto dynamically generatedGroupedPublishers.final <Key> Publisher<GroupedPublisher<Key,T>> Splits items from thisPublisherinto dynamically generatedGroupedPublishers.final <Key> Publisher<GroupedPublisher<Key,T>> Splits items from thisPublisherinto dynamically generatedGroupedPublishers.final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit) The semantics are identical togroupBy(Function, int)except that thekeySelectorcan map each data to multiple keys.final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit, int expectedGroupCountHint) The semantics are identical togroupBy(Function, int)except that thekeySelectorcan map each data to multiple keys.protected abstract voidhandleSubscribe(PublisherSource.Subscriber<? super T> subscriber) Handles a subscriber to thisPublisher.final CompletableIgnores all elements emitted by thisPublisherand forwards the termination signal to the returnedCompletable.final <R> Publisher<R>liftAsync(PublisherOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators.final <R> Publisher<R>liftSync(PublisherOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators.final <R> Single<R>liftSyncToSingle(PublisherToSingleOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators.final <R> Publisher<R>Transforms elements emitted by thisPublisherinto a different type.Merge twoPublishers together.static <T> Publisher<T>Merge allPublishers together.static <T> Publisher<T>Merge allPublishers together.static <T> Publisher<T>mergeAllDelayError(int maxConcurrency, Publisher<? extends T>... publishers) Merge allPublishers together.static <T> Publisher<T>mergeAllDelayError(Publisher<? extends T>... publishers) Merge allPublishers together.mergeDelayError(Publisher<? extends T> other) Merge twoPublishers together.multicast(int minSubscribers) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers.multicast(int minSubscribers, boolean cancelUpstream) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers.multicast(int minSubscribers, int queueLimit) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers.multicast(int minSubscribers, int queueLimit, boolean cancelUpstream) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers.multicast(int minSubscribers, int queueLimit, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers.multicast(int minSubscribers, int queueLimit, Function<Throwable, Completable> terminalResubscribe) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers.multicastToExactly(int expectedSubscribers) Deprecated.Usemulticast(int).multicastToExactly(int expectedSubscribers, int queueLimit) Deprecated.Usemulticast(int, int).static <T> Publisher<T>never()Creates a newPublisherthat never emits any item to itsPublisherSource.Subscriberand never call any terminal methods on it.final <R> Publisher<R>Filters items so that only non-nullitems of typePublisherare emitted by the return value.onCompleteError(Supplier<? extends Throwable> errorSupplier) Transform thisPublishersPublisherSource.Subscriber.onComplete()signal intoPublisherSource.Subscriber.onError(Throwable)signal (unlessnullerror returned fromerrorSupplier).Transform errors emitted on thisPublisherinto aPublisherSource.Subscriber.onComplete()signal (e.g.onErrorComplete(Class<E> type) Transform errors emitted on thisPublisherwhich matchtypeinto aPublisherSource.Subscriber.onComplete()signal (e.g.onErrorComplete(Predicate<? super Throwable> predicate) Transform errors emitted on thisPublisherwhich matchpredicateinto aPublisherSource.Subscriber.onComplete()signal (e.g.onErrorMap(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisPublisherwhich matchtypeinto a different error.onErrorMap(Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisPublisherinto a different error.onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisPublisherwhich matchpredicateinto a different error.onErrorResume(Class<E> type, Function<? super E, ? extends Publisher<? extends T>> nextFactory) onErrorResume(Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) onErrorReturn(Class<E> type, Function<? super E, ? extends T> itemSupplier) Transform errors emitted on thisPublisherwhich matchtypeintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g.onErrorReturn(Function<? super Throwable, ? extends T> itemSupplier) Transform errors emitted on thisPublisherintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g.onErrorReturn(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends T> itemSupplier) Transform errors emitted on thisPublisherwhich matchpredicateintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g.Creates a newPublisherthat will use the passedExecutorto invoke allPublisherSource.Subscribermethods.publishOn(Executor executor, BooleanSupplier shouldOffload) Creates a newPublisherthat may use the passedExecutorto invoke allPublisherSource.Subscribermethods.range(int begin, int end) range(int begin, int end, int stride) repeat(IntPredicate shouldRepeat) repeatWhen(IntFunction<? extends Completable> repeatWhen) Re-subscribes to thisPublisherwhen it completes and theCompletablereturned by the suppliedIntFunctioncompletes successfully.replay(int history) Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut also retainshistoryof the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)which are emitted to new downstreamPublisherSource.Subscribers before emitting new signals.Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut also retainshistoryHintof the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)which are emitted to new downstreamPublisherSource.Subscribers before emitting new signals.replay(ReplayStrategy<T> replayStrategy) Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut will also retain some history ofPublisherSource.Subscriber.onNext(Object)signals according to theReplayStrategyreplayStrategy.replay(Supplier<ReplayAccumulator<T>> accumulatorSupplier) Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut will also retain some history ofPublisherSource.Subscriber.onNext(Object)signals according to theReplayAccumulatoraccumulatorSupplier.retry(boolean terminateOnNextException, BiIntPredicate<Throwable> shouldRetry) retry(BiIntPredicate<Throwable> shouldRetry) retryWhen(boolean terminateOnNextException, BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisPublisherif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully.retryWhen(BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisPublisherif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully.final <R> Publisher<R>scanWith(Supplier<? extends ScanWithMapper<? super T, ? extends R>> mapperSupplier) Deprecated.final <R> Publisher<R>scanWith(Supplier<R> initial, BiFunction<R, ? super T, R> accumulator) Apply aBiFunctionto eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisherand an accumulated state.final <R> Publisher<R>scanWithLifetime(Supplier<? extends ScanWithLifetimeMapper<? super T, ? extends R>> mapperSupplier) Deprecated.final <R> Publisher<R>scanWithLifetimeMapper(Supplier<? extends ScanLifetimeMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisheras well as optionally concat onePublisherSource.Subscriber.onNext(Object)signal before the terminal signal is emitted downstream.final <R> Publisher<R>scanWithMapper(Supplier<? extends ScanMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisheras well as optionally concat onePublisherSource.Subscriber.onNext(Object)signal before the terminal signal is emitted downstream.setContextOnSubscribe(ContextMap context) Deprecated.requiring this operator is a sign that there is a problem in your operator chain.Signifies that when the returnedPublisheris subscribed to, theAsyncContextwill be shared instead of making acopy.Skip items emitted by thisPublisheruntil the first time the predicate is not satisfied.protected final voidsubscribeInternal(PublisherSource.Subscriber<? super T> subscriber) A internal subscribe method similar toPublisherSource.subscribe(Subscriber)which can be used by different implementations to subscribe.subscribeOn(Executor executor) Creates a newPublisherthat will use the passedExecutorto invoke the following methods: AllPublisherSource.Subscriptionmethods. ThehandleSubscribe(PublisherSource.Subscriber)method. This method does not override precedingExecutors, if any, specified forthisPublisher.subscribeOn(Executor executor, BooleanSupplier shouldOffload) Creates a newPublisherthat may use the passedExecutorto invoke the following methods: AllPublisherSource.Subscriptionmethods. ThehandleSubscribe(PublisherSource.Subscriber)method. This method does not override precedingExecutors, if any, specified forthisPublisher.final <R> Publisher<R>final <R> Publisher<R>switchMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) final <R> Publisher<R>switchMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxDelayedErrorsHint) takeAtMost(long numElements) takeUntil(Completable until) Takes elements untilCompletableis terminated successfully or with failure.Takes elements whilePredicateistrueand then cancelPublisherSource.Subscriptionof thisPublisheronce it returnsfalse.Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls.Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls.Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls.Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls.timeoutDemand(long duration, TimeUnit unit) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.timeoutDemand(long duration, TimeUnit unit, Executor executor) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.timeoutDemand(Duration duration) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.timeoutDemand(Duration duration, Executor executor) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.timeoutTerminal(long duration, TimeUnit unit) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.timeoutTerminal(long duration, TimeUnit unit, Executor timeoutExecutor) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.timeoutTerminal(Duration duration) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.timeoutTerminal(Duration duration, Executor timeoutExecutor) Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination.final CompletionStage<Collection<T>>Convert thisPublisherinto aCompletionStagewith aCollectioncontaining the elements of thisPublisherupon successful termination.final <R> CompletionStage<R>toCompletionStage(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) Convert thisPublisherinto aCompletionStageof typePublisherwhich represents all elements of thisPublisherupon successful termination.final Future<Collection<T>>toFuture()Convert thisPublisherinto aFuturewith aCollectioncontaining the elements of thisPublisherupon successful termination.final <R> Future<R>toFuture(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) final InputStreamtoInputStream(Function<? super T, byte[]> serializer) Subscribes tothisPublisherand converts all signals received by thePublisherSource.Subscriberto the returnedInputStreamfollowing the below rules:PublisherSource.Subscriptionreceived byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is used to request more data when required.final InputStreamtoInputStream(Function<? super T, byte[]> serializer, int queueCapacity) Subscribes tothisPublisherand converts all signals received by thePublisherSource.Subscriberto the returnedInputStreamfollowing the below rules:PublisherSource.Subscriptionreceived byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is used to request more data when required.final BlockingIterable<T>final BlockingIterable<T>toIterable(int queueCapacityHint) Validate the outstanding demand (PublisherSource.Subscription.request(long)minusPublisherSource.Subscriber.onNext(Object)) does not go negative.validateOutstandingDemand(ObjLongConsumer<T> onNextConsumer, LongBinaryConsumer requestConsumer) Validate the outstanding demand (PublisherSource.Subscription.request(long)minusPublisherSource.Subscriber.onNext(Object)) does not go negative.whenCancel(Runnable onCancel) Invokes theonCancelRunnableargument whenCancellable.cancel()is called for Subscriptions of the returnedPublisher.whenFinally(TerminalSignalConsumer doFinally) Invokes the corresponding method onwhenFinallyTerminalSignalConsumerargument 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.whenFinally(Runnable doFinally) Invokes thewhenFinallyRunnableargument exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()forPublisherSource.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.whenOnComplete(Runnable onComplete) Invokes theonCompleteRunnableargument whenPublisherSource.Subscriber.onComplete()is called forPublisherSource.Subscribers of the returnedPublisher.whenOnError(Consumer<Throwable> onError) Invokes theonErrorConsumerargument whenPublisherSource.Subscriber.onError(Throwable)is called forPublisherSource.Subscribers of the returnedPublisher.whenOnNext(Consumer<? super T> onNext) Invokes theonNextConsumerargument whenPublisherSource.Subscriber.onNext(Object)is called forPublisherSource.Subscribers of the returnedPublisher.whenOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribeConsumerargument whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher.whenRequest(LongConsumer onRequest) Invokes theonRequestLongConsumerargument whenPublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher.whenSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes methods on thatPublisherSource.Subscriberwhen the corresponding methods are called forPublisherSource.Subscribers of the returnedPublisher.whenSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription(via thesubscriptionSupplierargument) for each new subscribe and invokes all thePublisherSource.Subscriptionmethods when the corresponding methods are called forPublisherSource.Subscriptions of the returnedPublisher.
-
Constructor Details
-
Publisher
protected Publisher()New instance.
-
-
Method Details
-
map
Transforms elements emitted by thisPublisherinto a different type.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { results.add(mapper.apply(t)); } return results; -
cast
Cast thisPublisherfrom typePublisherto typePublisher.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { results.add(clazz.cast(t)); } return results;- Type Parameters:
R- The resulting type of the cast operation.- Parameters:
clazz- The type to cast to.- Returns:
- The cast of this
Publisherto typePublisher. Terminates with aClassCastExceptionif signals cannot be cast to typePublisher. - See Also:
-
filter
Filters items emitted by thisPublisher.This method provides a data transformation in sequential programming similar to:
List<T> results = ...; for (T t : resultOfThisPublisher()) { if (predicate.test(t)) { results.add(t); } } return results;- Parameters:
predicate- for the filter.- Returns:
- A
Publisherthat only emits the items that pass thepredicate. - See Also:
-
ofType
Filters items so that only non-nullitems of typePublisherare emitted by the return value.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; for (T t : resultOfThisPublisher()) { if (clazz.isInstance(t)) { results.add((R) t); } } return results;- Type Parameters:
R- The resulting type of the cast operation.- Parameters:
clazz- The type to filter and cast to.- Returns:
- a
Publisherthat only emits - See Also:
-
distinct
Only emits distinct signals observed by thisPublisher. Signals are compared usingObject.hashCode()andObject.equals(Object).This method provides a data transformation in sequential programming similar to:
Set<T> results = ...; for (T t : resultOfThisPublisher()) { results.add(t); } return results; -
scanWith
Apply aBiFunctionto eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisherand 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
Publisherthat transforms elements emitted by thisPublisherinto a different type. - See Also:
-
scanWith
@Deprecated public final <R> Publisher<R> scanWith(Supplier<? extends ScanWithMapper<? super T, ? extends R>> mapperSupplier) Deprecated.Apply a function to eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisheras 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
Publisherthat transforms elements emitted by thisPublisherinto a different type. - See Also:
-
scanWithMapper
public final <R> Publisher<R> scanWithMapper(Supplier<? extends ScanMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisheras well as optionally concat onePublisherSource.Subscriber.onNext(Object)signal before the terminal signal is emitted downstream.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithLifetimeMapperExt<T, R> mapper = mapperSupplier.get(); MappedTerminal<R> mapped = null; try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { mapped = mapper.mapOnError(cause); if (mapped == null) { throw cause; } } if (mapped == null) { mapped = mapper.mapOnComplete(); } if (mapped.onNextValid()) { results.add(mapped.onNext()); } if (mapped.terminal() != null) { throw mapped.terminal(); } return results;- Type Parameters:
R- Type of the items emitted by the returnedPublisher.- Parameters:
mapperSupplier- Invoked on eachPublisherSource.subscribe(Subscriber)and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber.- Returns:
- A
Publisherthat transforms elements emitted by thisPublisherinto a different type. - See Also:
-
scanWithLifetime
@Deprecated public final <R> Publisher<R> scanWithLifetime(Supplier<? extends ScanWithLifetimeMapper<? super T, ? extends R>> mapperSupplier) Deprecated.Apply a function to eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisheras well as optionally concat onePublisherSource.Subscriber.onNext(Object)signal before the terminal signal is emitted downstream. Additionally theScanWithLifetimeMapper.afterFinally()method will be invoked on terminal or cancel signals which enables cleanup of state (if required). This provides a similar lifetime management asTerminalSignalConsumer.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithLifetimeMapper<T, R> mapper = mapperSupplier.get(); try { try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { if (mapTerminal.test(state)) { results.add(mapper.mapOnError(cause)); return; } throw cause; } if (mapTerminal.test(state)) { results.add(mapper.mapOnComplete()); } } finally { mapper.afterFinally(); } return results;- Type Parameters:
R- Type of the items emitted by the returnedPublisher.- Parameters:
mapperSupplier- Invoked on eachPublisherSource.subscribe(Subscriber)and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber.- Returns:
- A
Publisherthat transforms elements emitted by thisPublisherinto a different type. - See Also:
-
scanWithLifetimeMapper
public final <R> Publisher<R> scanWithLifetimeMapper(Supplier<? extends ScanLifetimeMapper<? super T, ? extends R>> mapperSupplier) Apply a function to eachPublisherSource.Subscriber.onNext(Object)emitted by thisPublisheras well as optionally concat onePublisherSource.Subscriber.onNext(Object)signal before the terminal signal is emitted downstream. Additionally theScanLifetimeMapper.afterFinally()method will be invoked on terminal or cancel signals which enables cleanup of state (if required). This provides a similar lifetime management asTerminalSignalConsumer.This method provides a data transformation in sequential programming similar to:
List<R> results = ...; ScanWithLifetimeMapperExt<T, R> mapper = mapperSupplier.get(); try { MappedTerminal<R> mapped = null; try { for (T t : resultOfThisPublisher()) { results.add(mapper.mapOnNext(t)); } } catch (Throwable cause) { mapped = mapper.mapOnError(cause); if (mapped == null) { throw cause; } } if (mapped == null) { mapped = mapper.mapOnComplete(); } if (mapped.onNextValid()) { results.add(mapped.onNext()); } if (mapped.terminal() != null) { throw mapped.terminal(); } } finally { mapper.afterFinally(); } return results;- Type Parameters:
R- Type of the items emitted by the returnedPublisher.- Parameters:
mapperSupplier- Invoked on eachPublisherSource.subscribe(Subscriber)and maintains any necessary state for the mapping/accumulation for eachPublisherSource.Subscriber.- Returns:
- A
Publisherthat transforms elements emitted by thisPublisherinto a different type. - See Also:
-
onErrorComplete
Transform errors emitted on thisPublisherinto aPublisherSource.Subscriber.onComplete()signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { // ignored } return results;- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherinto aPublisherSource.Subscriber.onComplete()signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisPublisherwhich matchtypeinto aPublisherSource.Subscriber.onComplete()signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!type.isInstance(cause)) { throw cause; } } return results;- Type Parameters:
E- TheThrowabletype.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherwhich matchtypeinto aPublisherSource.Subscriber.onComplete()signal (e.g. swallows the error). - See Also:
-
onErrorComplete
Transform errors emitted on thisPublisherwhich matchpredicateinto aPublisherSource.Subscriber.onComplete()signal (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!predicate.test(cause)) { throw cause; } } return results;- Parameters:
predicate- returnstrueif theThrowableshould be transformed to andPublisherSource.Subscriber.onComplete()signal. Returnsfalseto propagate the error.- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherwhich matchpredicateinto aPublisherSource.Subscriber.onComplete()signal (e.g. swallows the error). - See Also:
-
onErrorReturn
Transform errors emitted on thisPublisherintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { results.add(itemSupplier.apply(cause)); } return results;- Parameters:
itemSupplier- returns the element to emit toPublisherSource.Subscriber.onNext(Object).- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g. swallows the error). - See Also:
-
onErrorReturn
public final <E extends Throwable> Publisher<T> onErrorReturn(Class<E> type, Function<? super E, ? extends T> itemSupplier) Transform errors emitted on thisPublisherwhich matchtypeintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!type.isInstance(cause)) { throw cause; } results.add(itemSupplier.apply(cause)); } return results;- Type Parameters:
E- The type ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.itemSupplier- returns the element to emit toPublisherSource.Subscriber.onNext(Object).- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g. swallows the error). - See Also:
-
onCompleteError
Transform thisPublishersPublisherSource.Subscriber.onComplete()signal intoPublisherSource.Subscriber.onError(Throwable)signal (unlessnullerror returned fromerrorSupplier).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); terminalOfThisPublisher(); Throwable cause = errorSupplier.get() if (cause != null) { throw cause; }- Parameters:
errorSupplier- returns the error to emit toPublisherSource.Subscriber.onError(Throwable). if the return value isnullthen complete withPublisherSource.Subscriber.onComplete().- Returns:
- A
Publisherwhich transform thisPublishersPublisherSource.Subscriber.onComplete()signal intoPublisherSource.Subscriber.onError(Throwable)signal (unlessnullerror returned fromerrorSupplier).
-
onErrorReturn
public final Publisher<T> onErrorReturn(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends T> itemSupplier) Transform errors emitted on thisPublisherwhich matchpredicateintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g. swallows the error).This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (!predicate.test(cause)) { throw cause; } results.add(itemSupplier.apply(cause)); } return result;- Parameters:
predicate- returnstrueif theThrowableshould be transformed toPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals. Returnsfalseto propagate the error.itemSupplier- returns the element to emit toPublisherSource.Subscriber.onNext(Object).- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherintoPublisherSource.Subscriber.onNext(Object)thenPublisherSource.Subscriber.onComplete()signals (e.g. swallows the error). - See Also:
-
onErrorMap
Transform errors emitted on thisPublisherinto a different error.This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { throw mapper.apply(cause); } return results; -
onErrorMap
public final <E extends Throwable> Publisher<T> onErrorMap(Class<E> type, Function<? super E, ? extends Throwable> mapper) Transform errors emitted on thisPublisherwhich matchtypeinto a different error.This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (type.isInstance(cause)) { throw mapper.apply(cause); } else { throw cause; } } return results;- Type Parameters:
E- The type ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.mapper- returns the error used to terminate the returnedPublisher.- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherinto a different error. - See Also:
-
onErrorMap
public final Publisher<T> onErrorMap(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Throwable> mapper) Transform errors emitted on thisPublisherwhich matchpredicateinto a different error.This method provides a data transformation in sequential programming similar to:
List<T> results = resultOfThisPublisher(); try { terminalOfThisPublisher(); } catch (Throwable cause) { if (predicate.test(cause)) { throw mapper.apply(cause); } else { throw cause; } } return results;- Parameters:
predicate- returnstrueif theThrowableshould be transformed viamapper. Returnsfalseto propagate the original error.mapper- returns the error used to terminate the returnedPublisher.- Returns:
- A
Publisherwhich transform errors emitted on thisPublisherinto a different error. - See Also:
-
onErrorResume
public final Publisher<T> onErrorResume(Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) Recover from any error emitted by thisPublisherby using anotherPublisherprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } return results; -
onErrorResume
public final <E extends Throwable> Publisher<T> onErrorResume(Class<E> type, Function<? super E, ? extends Publisher<? extends T>> nextFactory) Recover from errors emitted by thisPublisherwhich matchtypeby using anotherPublisherprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { if (type.isInstance(cause)) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } else { throw cause; } } return results;- Type Parameters:
E- The type ofThrowableto transform.- Parameters:
type- TheThrowabletype to filter, operator will not apply for errors which don't match this type.nextFactory- Returns the nextPublisher, when thisPublisheremits an error.- Returns:
- A
Publisherthat recovers from an error from thisPublisherby using anotherPublisherprovided by the passednextFactory. - See Also:
-
onErrorResume
public final Publisher<T> onErrorResume(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Publisher<? extends T>> nextFactory) Recover from errors emitted by thisPublisherwhich matchpredicateby using anotherPublisherprovided by the passednextFactory.This method provides similar capabilities to a try/catch block in sequential programming:
List<T> results; try { results = resultOfThisPublisher(); } catch (Throwable cause) { if (predicate.test(cause)) { // Note that nextFactory returning a error Publisher is like re-throwing (nextFactory shouldn't throw). results = nextFactory.apply(cause); } else { throw cause; } } return results;- Parameters:
predicate- returnstrueif theThrowableshould be transformed vianextFactory. Returnsfalseto propagate the original error.nextFactory- Returns the nextPublisher, when thisPublisheremits an error.- Returns:
- A
Publisherthat recovers from an error from thisPublisherby using anotherPublisherprovided by the passednextFactory. - See Also:
-
flatMapMerge
public final <R> Publisher<R> flatMapMerge(Function<? super T, ? extends Publisher<? extends R>> mapper) Map each element of thisPublisherinto aPublisher<Publisher> and flatten all signals emitted from each mappedPublisher<Publisher> into the returnedPublisher<Publisher>.To control the amount of concurrent processing done by this operator see
flatMapMerge(Function, int).This method is similar to
map(Function)but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results; -
flatMapMerge
public final <R> Publisher<R> flatMapMerge(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) Map each element of thisPublisherinto aPublisher<Publisher> and flatten all signals emitted from each mappedPublisher<Publisher> into the returnedPublisher<Publisher>.This method is similar to
map(Function)but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results; -
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) Map each element of thisPublisherinto 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 mappedPublisherreturned bymapper, terminates with an error, the returnedPublisherwill not immediately terminate. Instead, it will wait for thisPublisherand all mappedPublishers to terminate and then terminate the returnedPublisherwith all errors emitted by the mappedPublishers.To control the amount of concurrent processing done by this operator see
flatMapMergeDelayError(Function, int).This method is similar to
map(Function)but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors); -
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency) Map each element of thisPublisherinto 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 mappedPublisherreturned bymapper, terminates with an error, the returnedPublisherwill not immediately terminate. Instead, it will wait for thisPublisherand all mappedPublishers to terminate and then terminate the returnedPublisherwith all errors emitted by the mappedPublishers.This method is similar to
map(Function)but the result is an asynchronous stream, and provides a data transformation in sequential programming similar to:Executor e = ...; List<T> tResults = resultOfThisPublisher(); List<R> rResults = ...; // assume this is thread safe List<Throwable> errors = ...; // assume this is thread safe CountDownLatch latch = new CountDownLatch(tResults.size()); for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. e.execute(() -> { try { List<R> rList = mapper.apply(t); // Asynchronous result is flatten into a value by this operator. rResults.addAll(rList); } catch (Throwable cause) { errors.add(cause); // Asynchronous error is flatten into an error by this operator. } finally { latch.countdown(); } }); } latch.await(); if (errors.isEmpty()) { return rResults; } createAndThrowACompositeException(errors); -
flatMapMergeDelayError
public final <R> Publisher<R> flatMapMergeDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) Map each element of thisPublisherinto 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 mappedPublisherreturned bymapper, terminates with an error, the returnedPublisherwill not immediately terminate. Instead, it will wait for thisPublisherand all mappedPublishers to terminate and then terminate the returnedPublisherwith all errors emitted by the mappedPublishers.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 thisPublisherinto 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
Publisherwhich flattens the emissions from all mappedPublishers. - See Also:
-
flatMapMergeSingle
public final <R> Publisher<R> flatMapMergeSingle(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisherinto aSingle<Publisher> and flatten all signals emitted from each mappedSingle<Publisher> into the returnedPublisher<Publisher>.To control the amount of concurrent processing done by this operator see
flatMapMergeSingle(Function, int).Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { R r = future.get(); // Throws if the processing for this item failed. results.add(r); } return results; -
flatMapMergeSingle
public final <R> Publisher<R> flatMapMergeSingle(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisherinto aSingle<Publisher> and flatten all signals emitted from each mappedSingle<Publisher> into the returnedPublisher<Publisher>.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<R> future : futures) { R r = future.get(); // Throws if the processing for this item failed. results.add(r); } return results;- Type Parameters:
R- Type of items emitted by the returnedPublisher.- Parameters:
mapper-Functionto convert each item emitted by thisPublisherinto aSingle.maxConcurrency- Maximum activeSingles at any time. Even if the number of items requested by aPublisherSource.Subscriberis more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisherthat emits all items emitted by each single produced bymapper. - See Also:
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper) Map each element of thisPublisherinto 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 anySinglereturned bymapper, terminates with an error, the returnedPublisherwill not immediately terminate. Instead, it will wait for thisPublisherand allSingles to terminate and then terminate the returnedPublisherwith errors emitted by theSingles produced by themapper.To control the amount of concurrent processing done by this operator see
flatMapMergeSingleDelayError(Function, int).This method is similar to
map(Function)but the result is asynchronous, unordered, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { processResult(mapper.apply(t)); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); -
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisherinto 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 anySinglereturned bymapper, terminates with an error, the returnedPublisherwill not immediately terminate. Instead, it will wait for thisPublisherand allSingles to terminate and then terminate the returnedPublisherwith all errors emitted by theSingles produced by themapper.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { processResult(mapper.apply(t)); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);- Type Parameters:
R- Type of items emitted by the returnedPublisher.- Parameters:
mapper-Functionto convert each item emitted by thisPublisherinto aSingle.maxConcurrency- Maximum activeSingles at any time. Even if the number of items requested by aPublisherSource.Subscriberis more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisherthat emits all items emitted by each single produced bymapper. - See Also:
-
flatMapMergeSingleDelayError
public final <R> Publisher<R> flatMapMergeSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency, int maxDelayedErrorsHint) This method is similar tomap(Function)but the result is asynchronous and results are unordered. More specifically, map each element of thisPublisherinto 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 anySinglereturned bymapper, terminates with an error, the returnedPublisherwill not immediately terminate. Instead, it will wait for thisPublisherand allSingles to terminate and then terminate the returnedPublisherwith errors emitted by theSingles produced by themapper.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { processResult(mapper.apply(t)); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);- Type Parameters:
R- Type of items emitted by the returnedPublisher.- Parameters:
mapper-Functionto convert each item emitted by thisPublisherinto aSingle.maxConcurrency- Maximum activeSingles at any time. Even if the number of items requested by aPublisherSource.Subscriberis 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
Publisherthat emits all items emitted by each single produced bymapper. - See Also:
-
flatMapCompletable
Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.If the returned
Completableshould wait for the termination of all mappedCompletables 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-Functionto convert each item emitted by thisPublisherinto aCompletable.- Returns:
- A new
Completablethat terminates successfully if all the intermediateCompletables have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletable
public final Completable flatMapCompletable(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.If the returned
Completableshould wait for the termination of all mappedCompletables 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 thisPublisherinto aCompletable.maxConcurrency- Maximum activeCompletables at any time.- Returns:
- A new
Completablethat terminates successfully if all the intermediateCompletables have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.If any mapped
Completableterminates with an error the returnedCompletablewill not immediately terminate. Instead, it will wait for thisPublisherand all mappedCompletables to terminate.To control the amount of concurrent processing done by this operator see
flatMapCompletableDelayError(Function, int).This method is similar to
map(Function)but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { mapper.apply(t); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);- Parameters:
mapper- Function to convert each item emitted by thisPublisherinto aCompletable.- Returns:
- A new
Completablethat terminates successfully if all the intermediateCompletables have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper, int maxConcurrency) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.If any mapped
Completableterminates with an error the returnedCompletablewill not immediately terminate. Instead, it will wait for thisPublisherand all mappedCompletables to terminate.This method is similar to
map(Function)but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { mapper.apply(t); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);- Parameters:
mapper- Function to convert each item emitted by thisPublisherinto aCompletable.maxConcurrency- Maximum activeCompletables at any time.- Returns:
- A new
Completablethat terminates successfully if all the intermediateCompletables have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapCompletableDelayError
public final Completable flatMapCompletableDelayError(Function<? super T, ? extends Completable> mapper, int maxConcurrency, int maxDelayedErrorsHint) Map each element of thisPublisherinto aCompletableand flatten all signals such that the returnedCompletableterminates when all mappedCompletables have terminated successfully or any one of them has terminated with a failure.If any mapped
Completableterminates with an error the returnedCompletablewill not immediately terminate. Instead, it will wait for thisPublisherand all mappedCompletables to terminate.This method is similar to
map(Function)but the result is asynchronous, and provides a data transformation in sequential programming similar to:ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { mapper.apply(t); return null; })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);- Parameters:
mapper- Function to convert each item emitted by thisPublisherinto aCompletable.maxConcurrency- Maximum activeCompletables 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
Completablethat terminates successfully if all the intermediateCompletables have terminated successfully or any one of them has terminated with a failure. - See Also:
-
flatMapConcatSingle
public final <R> Publisher<R> flatMapConcatSingle(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)but the result is asynchronous. More specifically, map each element of thisPublisherinto aSingle<Publisher> and flatten all signals emitted from each mappedSingle<Publisher> into the returnedPublisher<Publisher>. Each mappedSingle<Publisher> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher.To control the amount of concurrent processing done by this operator see
flatMapConcatSingle(Function, int).Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } for (Future<R> future : futures) { processResult(future.get()); // Throws if the processing for this item failed. } -
flatMapConcatSingle
public final <R> Publisher<R> flatMapConcatSingle(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous. More specifically, map each element of thisPublisherinto aSingle<Publisher> and flatten all signals emitted from each mappedSingle<Publisher> into the returnedPublisher<Publisher>. Each mappedSingle<Publisher> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } for (Future<R> future : futures) { processResult(future.get()); // Throws if the processing for this item failed. }- Type Parameters:
R- Type of items emitted by the returnedPublisher.- Parameters:
mapper-Functionto convert each item emitted by thisPublisherinto aSingle.maxConcurrency- Maximum activeSingles at any time. Even if the number of items requested by aPublisherSource.Subscriberis more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisherthat emits all items emitted by each single produced bymapper. - See Also:
-
flatMapConcatSingleDelayError
public final <R> Publisher<R> flatMapConcatSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper) This method is similar tomap(Function)but the result is asynchronous. More specifically, map each element of thisPublisherinto aSingle<Publisher> and flatten all signals emitted from each mappedSingle<Publisher> into the returnedPublisher<Publisher>. Each mappedSingle<Publisher> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher.The behavior is the same as
flatMapConcatSingle(Function)with the exception that if anySinglereturned bymapper, terminates with an error, the returnedPublisherwill not terminate until thisPublisherand allSingles to terminate.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { processResult(future.get()); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); -
flatMapConcatSingleDelayError
public final <R> Publisher<R> flatMapConcatSingleDelayError(Function<? super T, ? extends Single<? extends R>> mapper, int maxConcurrency) This method is similar tomap(Function)but the result is asynchronous. More specifically, map each element of thisPublisherinto aSingle<Publisher> and flatten all signals emitted from each mappedSingle<Publisher> into the returnedPublisher<Publisher>. Each mappedSingle<Publisher> maybe subscribed to concurrently but the results are emitted in the same order as thisPublisher.The behavior is the same as
flatMapConcatSingle(Function)with the exception that if anySinglereturned bymapper, terminates with an error, the returnedPublisherwill not terminate until thisPublisherand allSingles to terminate.Provides a data transformation in sequential programming similar to:
ExecutorService e = ...; List<Future<R>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { processResult(future.get()); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors);- Type Parameters:
R- Type of items emitted by the returnedPublisher.- Parameters:
mapper-Functionto convert each item emitted by thisPublisherinto aSingle.maxConcurrency- Maximum activeSingles at any time. Even if the number of items requested by aPublisherSource.Subscriberis more than this number, this will never request more than this number at any point.- Returns:
- A new
Publisherthat emits all items emitted by each single produced bymapper. - See Also:
-
flatMapConcatIterable
public final <R> Publisher<R> flatMapConcatIterable(Function<? super T, ? extends Iterable<? extends R>> mapper) Create aPublisherthat flattens each element returned by theIterable.iterator()frommapper.The mapper
Functionwill only be called when the previously returnedIteratorhas returnedfalsefromIterator.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- AFunctionthat returns anIterablefor each element.- Returns:
- a
Publisherthat flattens each element returned by theIterable.iterator()frommapper. The results will be sequential for eachIterator, and overall for all calls toIterable.iterator()
-
switchMap
public final <R> Publisher<R> switchMap(Function<? super T, ? extends Publisher<? extends R>> mapper) Return aPublisherthat will switch to the latestPublisheremitted frommapperand the priorPublisherwill be cancelled. Both upstream and the last switchedPublishermust complete before the returnedPublishercompletes. If either upstream or the currently activePublisherterminate in error the returnedPublisheris terminated with that error.ExecutorService e = ...; List<Future<List<R>>> futures = ...; // assume this is thread safe for (T t : resultOfThisPublisher()) { // Note that flatMap process results in parallel. futures.add(e.submit(() -> { // Approximation: control flow is simplified here but when a later mapper is applied any incomplete // results from a previous mapper are cancelled and result in empty results. return mapper.apply(t); // Asynchronous result is flatten into a value by this operator. })); } List<R> results = new ArrayList<>(futures.size()); // This is an approximation, this operator does not provide any ordering guarantees for the results. for (Future<List<R>> future : futures) { List<R> rList = future.get(); // Throws if the processing for this item failed. results.addAll(rList); } return results; -
switchMapDelayError
public final <R> Publisher<R> switchMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper) Return aPublisherthat will switch to the latestPublisheremitted frommapperand the priorPublisherwill be cancelled. Both upstream and the last switchedPublishermust terminate before the returnedPublisherterminates (including errors). -
switchMapDelayError
public final <R> Publisher<R> switchMapDelayError(Function<? super T, ? extends Publisher<? extends R>> mapper, int maxDelayedErrorsHint) Return aPublisherthat will switch to the latestPublisheremitted frommapperand the priorPublisherwill be cancelled. Both upstream and the last switchedPublishermust terminate before the returnedPublisherterminates (including errors).- Type Parameters:
R- The type of mappedPublisher.- Parameters:
mapper- Convert each item emitted by thisPublisherinto anotherPublisher.maxDelayedErrorsHint- The maximum amount of errors that will be queued. After this point exceptions maybe discarded to reduce memory consumption.- Returns:
- A
Publisherthat will switch to the latestPublisheremitted frommapperand the priorPublisherwill be cancelled. - See Also:
-
merge
Merge twoPublishers together. There is no guaranteed ordering of events emitted from the returnedPublisher.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfThisPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. } return mergedResults; -
mergeDelayError
Merge twoPublishers together. There is no guaranteed ordering of events emitted from the returnedPublisher. If eitherPublisherfails the error propagation will be delayed until both terminate.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfThisPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); return mergedResults; -
whenOnSubscribe
public final Publisher<T> whenOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribeConsumerargument whenPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher.The order in which
onSubscribewill 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenOnNext
Invokes theonNextConsumerargument whenPublisherSource.Subscriber.onNext(Object)is called forPublisherSource.Subscribers of the returnedPublisher.The order in which
onNextwill 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenOnComplete
Invokes theonCompleteRunnableargument whenPublisherSource.Subscriber.onComplete()is called forPublisherSource.Subscribers of the returnedPublisher.The order in which
onCompletewill 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenOnError
Invokes theonErrorConsumerargument whenPublisherSource.Subscriber.onError(Throwable)is called forPublisherSource.Subscribers of the returnedPublisher.The order in which
onErrorwill 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenFinally
Invokes thewhenFinallyRunnableargument exactly once, when any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()
PublisherSource.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.The order in which
whenFinallywill 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenFinally
Invokes the corresponding method onwhenFinallyTerminalSignalConsumerargument 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher.The order in which
whenFinallywill 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 thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Publisher. - See Also:
-
whenRequest
Invokes theonRequestLongConsumerargument whenPublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher.- Parameters:
onRequest- Invoked whenPublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenCancel
Invokes theonCancelRunnableargument whenCancellable.cancel()is called for Subscriptions of the returnedPublisher.The order in which
whenFinallywill be invoked relative toCancellable.cancel()is undefined. If you need strict ordering seebeforeCancel(Runnable)andafterCancel(Runnable).- Parameters:
onCancel- Invoked whenCancellable.cancel()is called for Subscriptions of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
validateOutstandingDemand
Validate the outstanding demand (PublisherSource.Subscription.request(long)minusPublisherSource.Subscriber.onNext(Object)) does not go negative. This can be a useful diagnostic tool if custom operators or async sources are in use to ensure outstanding demand is always non-negative.Invalid
PublisherSource.Subscription.request(long)maybe propagated by this operator, and is still the responsibility of upstream source to terminate in error.Here is pseudo-code demonstrating the functionality of this operator:
request(1); onNext(t1); onNext(t2); // throws an Exception because outstanding demand is 0- Returns:
- The new
Publisher. - See Also:
-
validateOutstandingDemand
public final Publisher<T> validateOutstandingDemand(ObjLongConsumer<T> onNextConsumer, LongBinaryConsumer requestConsumer) Validate the outstanding demand (PublisherSource.Subscription.request(long)minusPublisherSource.Subscriber.onNext(Object)) does not go negative. This can be a useful diagnostic tool if custom operators or async sources are in use to ensure outstanding demand is always non-negative.ReactiveStreams specification allows
PublisherSource.SubscriberandPublisherSource.Subscriptionto be concurrent, therefore the arguments of this function maybe invoked concurrently.Invalid
PublisherSource.Subscription.request(long)maybe propagated by this operator, and is still the responsibility of upstream source to terminate in error.Here is pseudo-code demonstrating the functionality of this operator:
request(1); // calls requestConsumer(1, 1) onNext(t1); // calls onNextConsumer(t1, 0) onNext(t2); // calls onNextConsumer(t1, -1), throws an Exception because outstanding demand is 0- Parameters:
onNextConsumer- Called whenPublisherSource.Subscriber.onNext(Object)is invoked with first argument is the signal and second argument is demand (after decrementing). This consumer is meant to be used for observability purposes, and is assumed to not throw.requestConsumer- Called whenPublisherSource.Subscription.request(long)is invoked with first argument ofnand second argument of current demand (after incrementing). This method may only be called ifnis valid. This consumer is meant to be used for observability purposes, and is assumed to not throw.- Returns:
- The new
Publisher.
-
timeout
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.unit- The units forduration.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeout
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeout
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.unit- The units forduration.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeout
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between adjacentPublisherSource.Subscriber.onNext(Object)calls. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeoutTerminal
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration during which the Publisher must complete.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. - See Also:
-
timeoutTerminal
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration during which the Publisher must complete.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. - See Also:
-
timeoutTerminal
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration during which the Publisher must complete.unit- The units forduration.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. - See Also:
-
timeoutTerminal
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. The timer starts when the returnedPublisheris subscribed.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration during which the Publisher must complete.unit- The units forduration.timeoutExecutor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses between subscribe and termination. - See Also:
-
timeoutDemand
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.unit- The units forduration.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeoutDemand
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.unit- The units forduration.executor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeoutDemand
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
timeoutDemand
Creates a newPublisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses while there is 0 outstanding demand.In the event of timeout any
PublisherSource.SubscriptionfromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)will becancelledand the associatedPublisherSource.Subscriberwill beterminated.- Parameters:
duration- The time duration which is allowed to elapse betweenPublisherSource.Subscriber.onNext(Object)calls.executor- TheExecutorto use for managing the timer notifications.- Returns:
- a new
Publisherthat will mimic the signals of thisPublisherbut will terminate with aTimeoutExceptionif timedurationelapses betweenPublisherSource.Subscriber.onNext(Object)calls. - See Also:
-
concat
Emits items emitted bynextPublisherafterthisPublisherterminates successfully.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); results.addAll(resultOfPublisher(next)); return results; -
concat
Listens and emits the result ofnextSingleafterthisPublisherterminates successfully.This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); results.add(resultOfSingle(next)); return results; -
concat
Listens for completion ofnextCompletableafterthisPublisherterminates successfully. Any error fromthisPublisherandnextCompletableis 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-Completableto wait for completion afterthisPublisherterminates successfully.- Returns:
- A
Publisherthat emits all items from thisPublisherand then awaits successful completion ofnextCompletable. - See Also:
-
concatPropagateCancel
This method is likeconcat(Completable)exceptnextwill be subscribed to and cancelled if thisPublisheris cancelled or terminates withPublisherSource.Subscriber.onError(Throwable).This method provides a means to sequence the execution of two asynchronous sources and in sequential programming is similar to:
List<T> results = resultOfThisPublisher(); resultOfCompletable(next); return results;- Parameters:
next-Completableto wait for completion afterthisPublisherterminates successfully. Will be subscribed to and cancelled if thisPublisheris cancelled or terminates withPublisherSource.Subscriber.onError(Throwable).- Returns:
- A
Publisherthat emits all items from thisPublisherand then awaits successful completion ofnextCompletable. - See Also:
-
retry
Re-subscribes to thisPublisherif an error is emitted and the passedBiIntPredicatereturnstrue.This method may result in a
This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1, results); } else { throw cause; } } }- Parameters:
shouldRetry-BiIntPredicatethat given the retry count and the most recentThrowableemitted from thisPublisherdetermines if the operation should be retried.- Returns:
- A
Publisherthat emits all items from thisPublisherand re-subscribes if an error is emitted if the passedBiIntPredicatereturnedtrue. - See Also:
-
retry
public final Publisher<T> retry(boolean terminateOnNextException, BiIntPredicate<Throwable> shouldRetry) Re-subscribes to thisPublisherif an error is emitted and the passedBiIntPredicatereturnstrue.This method may result in a
This method provides a means to retry an operation under certain failure conditions and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (!terminateOnNextException && shouldRetry.apply(attempts + 1, cause)) { return execute(attempts + 1, results); } else { throw cause; } } }- Parameters:
terminateOnNextException-truemeans that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)will be caught, cancel thePublisherSource.Subscription, propagate aPublisherSource.Subscriber.onError(Throwable)downstream, and no retry will be attempted.falsemeans that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)will NOT be caught and will propagate upstream. May lead to incorrect demand accounting and "hangs" if this operator isn't the last in the chain.
shouldRetry-BiIntPredicatethat given the retry count and the most recentThrowableemitted from thisPublisherdetermines if the operation should be retried.- Returns:
- A
Publisherthat emits all items from thisPublisherand re-subscribes if an error is emitted if the passedBiIntPredicatereturnedtrue. - See Also:
-
retryWhen
Re-subscribes to thisPublisherif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedPublisherterminates with that error.This method may result in a
This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1, results); } catch (Throwable ignored) { throw cause; } } }- Parameters:
retryWhen-BiIntFunctionthat given the retry count and the most recentThrowableemitted from thisPublisherreturns aCompletable. If thisCompletableemits an error, that error is emitted from the returnedPublisher, otherwise, originalPublisheris re-subscribed when thisCompletablecompletes.- Returns:
- A
Publisherthat emits all items from thisPublisherand re-subscribes if an error is emitted andCompletablereturned byBiIntFunctioncompletes successfully. - See Also:
-
retryWhen
public final Publisher<T> retryWhen(boolean terminateOnNextException, BiIntFunction<Throwable, ? extends Completable> retryWhen) Re-subscribes to thisPublisherif an error is emitted and theCompletablereturned by the suppliedBiIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedPublisherterminates with that error.This method may result in a
This method provides a means to retry an operation under certain failure conditions in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:retryWhen((i, cause) -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())public List<T> execute() { List<T> results = ...; return execute(0, results); } private List<T> execute(int attempts, List<T> results) { try { Iterator<T> itr = resultOfThisPublisher(); while (itr.hasNext()) { T t = itr.next(); // Any iteration with the Iterator may throw results.add(t); } return results; } catch (Throwable cause) { if (terminateOnNextException) { throw cause; } try { shouldRetry.apply(attempts + 1, cause); // Either throws or completes normally execute(attempts + 1, results); } catch (Throwable ignored) { throw cause; } } }- Parameters:
terminateOnNextException-truemeans that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)will be caught, cancel thePublisherSource.Subscription, propagate aPublisherSource.Subscriber.onError(Throwable)downstream, and no retry will be attempted.falsemeans that exceptions thrown from downstreamPublisherSource.Subscriber.onNext(Object)will NOT be caught and will propagate upstream. May lead to incorrect demand accounting and "hangs" if this operator isn't the last in the chain.
retryWhen-BiIntFunctionthat given the retry count and the most recentThrowableemitted from thisPublisherreturns aCompletable. If thisCompletableemits an error, that error is emitted from the returnedPublisher, otherwise, originalPublisheris re-subscribed when thisCompletablecompletes.- Returns:
- A
Publisherthat emits all items from thisPublisherand re-subscribes if an error is emitted andCompletablereturned byBiIntFunctioncompletes successfully. - See Also:
-
repeat
Re-subscribes to thisPublisherwhen it completes and the passedIntPredicatereturnstrue.This method may result in a
This method provides a means to repeat an operation multiple times and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())List<T> results = new ...; int i = 0; do { results.addAll(resultOfThisPublisher()); } while (shouldRepeat.test(++i)); return results;- Parameters:
shouldRepeat-IntPredicatethat given the repeat count determines if the operation should be repeated.- Returns:
- A
Publisherthat emits all items from thisPublisherand re-subscribes when it completes if the passedIntPredicatereturnstrue. - See Also:
-
repeatWhen
Re-subscribes to thisPublisherwhen it completes and theCompletablereturned by the suppliedIntFunctioncompletes successfully. If the returnedCompletableemits an error, the returnedPublisheris completed.This method may result in a
This method provides a means to repeat an operation multiple times when in an asynchronous fashion and in sequential programming is similar to:StackOverflowErrorif too many consecutive calls are made. This can be avoided by trampolining the call stack onto anExecutor. For example:repeatWhen(i -> i % 10 == 0 ? executor.submit(() -> { }) : Completable.completed())List<T> results = new ...; int i = 0; while (true) { results.addAll(resultOfThisPublisher()); try { repeatWhen.apply(++i); // Either throws or completes normally } catch (Throwable cause) { break; } } return results;- Parameters:
repeatWhen-IntFunctionthat given the repeat count returns aCompletable. If thisCompletableemits an error repeat is terminated, otherwise, originalPublisheris re-subscribed when thisCompletablecompletes.- Returns:
- A
Publisherthat emits all items from thisPublisherand re-subscribes if an error is emitted andCompletablereturned byIntFunctioncompletes successfully. - See Also:
-
skipWhile
Skip items emitted by thisPublisheruntil the first time the predicate is not satisfied.This method provides a data transformation in sequential programming similar to:
List<T> results = ...; boolean skipping = true; for (T t : resultOfThisPublisher()) { if (skipping) { skipping = predicate.test(t); } if (!skipping) { results.add(t); } } return results;- Parameters:
predicate- for evaluating whether to continue skipping items.- Returns:
- A
Publisherthat skips items until the predicate returns falsepredicate. - See Also:
-
firstAndTail
Converts thisPublisherto aSinglethat will contain the first element of thisPublisherand aPublisherrepresenting the remainder of the stream, to a mapping function.Note that either the packer function itself or any operator following this one MUST eventually take care of the tail
Publisheror they risk leaking resources or attached callbacks on the original Publisher. This includes cases where an exception is thrown instead of returning the packed object or a failed Single is returned. In addition, the tail may only be subscribed to exactly one time. SubsequentPublisherSource.Subscribers will receiveDuplicateSubscribeException, even if the original publisher supports re-subscribes.class Result { Result(T head, Iterator<T> tail) { this.head = head; this.tail = tail; } T head; Iterator<T> tail; } Iterator<T> itr = resultOfThisPublisher(); Result result = new Result(itr.next(), itr); return result;- Type Parameters:
R- The resulting type of the packer operation.- Parameters:
packer- A function that takes the head of the input stream and processes it, along with aPublisherof the remainder of the stream.- Returns:
- A
Singlecontaining the packed object that is a result of calling packer on the head and tail of the stream.
-
takeAtMost
Takes at mostnumElementselements fromthisPublisher.If no terminal event is received before receiving
numElementselements,PublisherSource.Subscriptionfor thePublisherSource.Subscriberis cancelled.This method provides a means to take a limited number of results from this
Publisherand in sequential programming is similar to:List<T> results = ...; int i = 0; for (T t : resultOfThisPublisher()) { if (++i > numElements) { break; } results.add(t); } return results; -
takeWhile
Takes elements whilePredicateistrueand then cancelPublisherSource.Subscriptionof thisPublisheronce it returnsfalse.This method provides a means to take a limited number of results from this
Publisherand 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-Predicatethat is checked before emitting any item to aPublisherSource.Subscriber. If this predicate returnstrue, that item is emitted, elsePublisherSource.Subscriptionis cancelled.- Returns:
- A
Publisherthat only emits the items as long as thePredicate.test(Object)method returnstrue. - See Also:
-
takeUntil
Takes elements untilCompletableis terminated successfully or with failure.This method provides a means to take a limited number of results from this
Publisherand in sequential programming is similar to:List<T> results = ...; for (T t : resultOfThisPublisher()) { if (isCompleted(until)) { break; } takeResults.add(t); } return results;- Parameters:
until-Completable, termination of which, terminates the returnedPublisher. If thisPublishermaybe resubscribed theCompletableshould be also, or usedefer(Supplier)to create a newCompletableon each subscribe.- Returns:
- A
Publisherthat only emits the items tilluntilCompletableis completed. - See Also:
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T, ? extends Key> keySelector) Splits items from thisPublisherinto dynamically generatedGroupedPublishers. Item to group association is done bykeySelectorFunction. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriberhas not yet cancelled itsPublisherSource.Subscription, this item is sent to thatPublisherSource.Subscriber. Otherwise a newGroupedPublisheris created and emitted from the returnedPublisher.Flow control
Multiple
PublisherSource.Subscribers (for multipleGroupedPublishers) request items individually from thisPublisher. Since, there is no way for aPublisherSource.Subscriberto only request elements for its group, elements requested by one group may end up producing items for a different group, which has not yet requested enough. This will cause items to be queued per group which can not be emitted due to lack of demand. This queue size can be controlled viagroupBy(Function, int).Cancellation
If the
PublisherSource.Subscriberof the returnedPublishercancels itsPublisherSource.Subscription, and there are no activeGroupedPublishersPublisherSource.Subscribers then upstream will be cancelled.PublisherSource.Subscribers of individualGroupedPublishers can cancel theirPublisherSource.Subscriptions at any point. If any new item is emitted for the cancelledGroupedPublisher, a newGroupedPublisherwill be emitted from the returnedPublisher. Any queued items for a cancelledPublisherSource.Subscriberfor aGroupedPublisherwill be discarded and hence will not be emitted if the sameGroupedPublisheris 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 ofGroupedPublisherkeys.- Parameters:
keySelector-Functionto assign an item emitted by thisPublisherto aGroupedPublisher.- Returns:
- A
Publisherthat emitsGroupedPublishers for newkeys as emitted bykeySelectorFunction. - See Also:
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T, ? extends Key> keySelector, int queueLimit) Splits items from thisPublisherinto dynamically generatedGroupedPublishers. Item to group association is done bykeySelectorFunction. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriberhas not yet cancelled itsPublisherSource.Subscription, this item is sent to thatPublisherSource.Subscriber. Otherwise a newGroupedPublisheris created and emitted from the returnedPublisher.Flow control
Multiple
PublisherSource.Subscribers (for multipleGroupedPublishers) request items individually from thisPublisher. Since, there is no way for aPublisherSource.Subscriberto 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 thequeueLimitargument.Cancellation
If the
PublisherSource.Subscriberof the returnedPublishercancels itsPublisherSource.Subscription, and there are no activeGroupedPublishersPublisherSource.Subscribers then upstream will be cancelled.PublisherSource.Subscribers of individualGroupedPublishers can cancel theirPublisherSource.Subscriptions at any point. If any new item is emitted for the cancelledGroupedPublisher, a newGroupedPublisherwill be emitted from the returnedPublisher. Any queued items for a cancelledPublisherSource.Subscriberfor aGroupedPublisherwill be discarded and hence will not be emitted if the sameGroupedPublisheris 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 ofGroupedPublisherkeys.- Parameters:
keySelector-Functionto assign an item emitted by thisPublisherto aGroupedPublisher.queueLimit- The number of elements which will be queued for each groupedPublisherSource.Subscriberin order to compensate for unequal demand. This also applies to the returnedPublisherwhich may also have to queue signals.- Returns:
- A
Publisherthat emitsGroupedPublishers for newkeys as emitted bykeySelectorFunction. - See Also:
-
groupBy
public final <Key> Publisher<GroupedPublisher<Key,T>> groupBy(Function<? super T, ? extends Key> keySelector, int queueLimit, int expectedGroupCountHint) Splits items from thisPublisherinto dynamically generatedGroupedPublishers. Item to group association is done bykeySelectorFunction. If the selector selects a key which is previously seen and its associatedPublisherSource.Subscriberhas not yet cancelled itsPublisherSource.Subscription, this item is sent to thatPublisherSource.Subscriber. Otherwise a newGroupedPublisheris created and emitted from the returnedPublisher.Flow control
Multiple
PublisherSource.Subscribers (for multipleGroupedPublishers) request items individually from thisPublisher. Since, there is no way for aPublisherSource.Subscriberto 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 thequeueLimitargument.Cancellation
If the
PublisherSource.Subscriberof the returnedPublishercancels itsPublisherSource.Subscription, and there are no activeGroupedPublishersPublisherSource.Subscribers then upstream will be cancelled.PublisherSource.Subscribers of individualGroupedPublishers can cancel theirPublisherSource.Subscriptions at any point. If any new item is emitted for the cancelledGroupedPublisher, a newGroupedPublisherwill be emitted from the returnedPublisher. Any queued items for a cancelledPublisherSource.Subscriberfor aGroupedPublisherwill be discarded and hence will not be emitted if the sameGroupedPublisheris 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 ofGroupedPublisherkeys.- Parameters:
keySelector-Functionto assign an item emitted by thisPublisherto aGroupedPublisher.queueLimit- The number of elements which will be queued for each groupedPublisherSource.Subscriberin order to compensate for unequal demand. This also applies to the returnedPublisherwhich may also have to queue signals.expectedGroupCountHint- Expected number of groups that would be emitted bythisPublisher. This is just a hint for internal data structures and does not have to be precise.- Returns:
- A
Publisherthat emitsGroupedPublishers for newkeys as emitted bykeySelectorFunction. - See Also:
-
groupToMany
public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit) The semantics are identical togroupBy(Function, int)except that thekeySelectorcan 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 ofGroupedPublisherkeys.- Parameters:
keySelector-Functionto assign an item emitted by thisPublisherto multipleGroupedPublishers.queueLimit- The number of elements which will be queued for each groupedPublisherSource.Subscriberin order to compensate for unequal demand. This also applies to the returnedPublisherwhich may also have to queue signals.Publisherreturned from this method not requesting enough viaPublisherSource.Subscription.request(long).- Returns:
- A
Publisherthat emitsGroupedPublishers for newkeys as emitted bykeySelectorFunction. - See Also:
-
groupToMany
public final <Key> Publisher<GroupedPublisher<Key,T>> groupToMany(Function<? super T, ? extends Iterator<? extends Key>> keySelector, int queueLimit, int expectedGroupCountHint) The semantics are identical togroupBy(Function, int)except that thekeySelectorcan 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 ofGroupedPublisherkeys.- Parameters:
keySelector-Functionto assign an item emitted by thisPublisherto multipleGroupedPublishers.queueLimit- The number of elements which will be queued for each groupedPublisherSource.Subscriberin order to compensate for unequal demand. This also applies to the returnedPublisherwhich may also have to queue signals.expectedGroupCountHint- Expected number of groups that would be emitted bythisPublisher. This is just a hint for internal data structures and does not have to be precise.- Returns:
- A
Publisherthat emitsGroupedPublishers for newkeys as emitted bykeySelectorFunction. - See Also:
-
multicastToExactly
Deprecated.Usemulticast(int).Create aPublisherthat 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.Subscribers and the first callsrequest(10), and the second only callsrequest(1), then 9 elements will be queued to deliver to second when morePublisherSource.Subscription.request(long)demand is made.In sequential programming this is similar to the following:
List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults; -
multicastToExactly
Deprecated.Usemulticast(int, int).Create aPublisherthat allows exactlyexpectedSubscriberssubscribes. The events from thisPublisherobject 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.Subscribers and the first callsrequest(10), and the second only callsrequest(1), then 9 elements will be queued to deliver to second when morePublisherSource.Subscription.request(long)demand is made.In sequential programming this is similar to the following:
List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
expectedSubscribers- The number of expected subscribe calls required on the returnedPublisherbefore subscribing to thisPublisher.queueLimit- The number of elements which will be queued for eachPublisherSource.Subscriberin order to compensate for unequal demand.- Returns:
- a
Publisherthat allows exactlyexpectedSubscriberssubscribes.
-
multicast
Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber.Downstream
PublisherSource.Subscribers may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscribersubscribed will not be queued.Upstream outstanding
Subscription demandmay be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscribers will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
minSubscribers- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscribersubscribe to the return value.- Returns:
- a
Publisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber. - See Also:
-
multicast
Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber.Downstream
PublisherSource.Subscribers may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscribersubscribed will not be queued.Upstream outstanding
Subscription demandmay be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscribers will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
minSubscribers- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscribersubscribe to the return value.cancelUpstream-trueif upstream should becancelledwhen all downstreamPublisherSource.Subscribers cancel.falsemeans that cancel will not be propagated upstream even if all downstreamPublisherSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.- Returns:
- a
Publisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber. - See Also:
-
multicast
Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber.Downstream
PublisherSource.Subscribers may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscribersubscribed will not be queued.Upstream outstanding
Subscription demandmay be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscribers will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
minSubscribers- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscribersubscribe to the return value.queueLimit- The number of elements which will be queued for eachPublisherSource.Subscriberin order to compensate for unequal demand.- Returns:
- a
Publisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber. - See Also:
-
multicast
Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber.Downstream
PublisherSource.Subscribers may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscribersubscribed will not be queued.Upstream outstanding
Subscription demandmay be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscribers will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
minSubscribers- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscribersubscribe to the return value.queueLimit- The number of elements which will be queued for eachPublisherSource.Subscriberin order to compensate for unequal demand.cancelUpstream-trueif upstream should becancelledwhen all downstreamPublisherSource.Subscribers cancel.falsemeans that cancel will not be propagated upstream even if all downstreamPublisherSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.- Returns:
- a
Publisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber. - See Also:
-
multicast
public final Publisher<T> multicast(int minSubscribers, int queueLimit, Function<Throwable, Completable> terminalResubscribe) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber.Downstream
PublisherSource.Subscribers may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscribersubscribed will not be queued.Upstream outstanding
Subscription demandmay be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscribers will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
minSubscribers- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscribersubscribe to the return value.queueLimit- The number of elements which will be queued for eachPublisherSource.Subscriberin order to compensate for unequal demand.terminalResubscribe- AFunctionthat is invoked when a terminal signal arrives from upstream, and returns aCompletablewhose termination resets the state of the returnedPublisherand allows for downstream resubscribing. The argument to this function is as follows:nullif upstream terminates withPublisherSource.Subscriber.onComplete()- otherwise the
ThrowablefromPublisherSource.Subscriber.onError(Throwable)
- Returns:
- a
Publisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber. - See Also:
-
multicast
public final Publisher<T> multicast(int minSubscribers, int queueLimit, boolean cancelUpstream, Function<Throwable, Completable> terminalResubscribe) Create aPublisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber.Downstream
PublisherSource.Subscribers may subscribe after the upstream subscribe, but signals that were delivered before the downstreamPublisherSource.Subscribersubscribed will not be queued.Upstream outstanding
Subscription demandmay be limited to provide an upper bound on queue sizes (e.g. demand from downstreamPublisherSource.Subscribers will vary). In sequential programming this is similar to the following:List<T> results = resultOfThisPublisher(); List<List<T>> multiResults = ...; // simulating multiple Subscribers for (int i = 0; i < expectedSubscribers; ++i) { multiResults.add(results); } return multiResults;- Parameters:
minSubscribers- The upstream subscribe operation will not happen until after this manyPublisherSource.Subscribersubscribe to the return value.queueLimit- The number of elements which will be queued for eachPublisherSource.Subscriberin order to compensate for unequal demand.cancelUpstream-trueif upstream should becancelledwhen all downstreamPublisherSource.Subscribers cancel.falsemeans that cancel will not be propagated upstream even if all downstreamPublisherSource.Subscribers cancel, and the upstream Subscription will stay valid until termination.terminalResubscribe- AFunctionthat is invoked when a terminal signal arrives from upstream, and returns aCompletablewhose termination resets the state of the returnedPublisherand allows for downstream resubscribing. The argument to this function is as follows:nullif upstream terminates withPublisherSource.Subscriber.onComplete()- otherwise the
ThrowablefromPublisherSource.Subscriber.onError(Throwable)
- Returns:
- a
Publisherthat subscribes a single time upstream but allows for multiple downstreamPublisherSource.Subscribers. Signals from upstream will be multicast to each downstreamPublisherSource.Subscriber. - See Also:
-
replay
Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut also retainshistoryof the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)which are emitted to new downstreamPublisherSource.Subscribers before emitting new signals.- Parameters:
history- max number of signals (excludingPublisherSource.Subscriber.onComplete()andPublisherSource.Subscriber.onError(Throwable)) to retain.- Returns:
- A
Publisherthat allows for multiple downstream subscribers and emits the previoushistoryPublisherSource.Subscriber.onNext(Object)signals to each new subscriber. - See Also:
-
replay
Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut also retainshistoryHintof the most recently emitted signals fromPublisherSource.Subscriber.onNext(Object)which are emitted to new downstreamPublisherSource.Subscribers before emitting new signals. Each item is only retained forttlduration of time.- Parameters:
historyHint- hint for max number of signals (excludingPublisherSource.Subscriber.onComplete()andPublisherSource.Subscriber.onError(Throwable)) to retain. Due to concurrency between threads (timer, accumulation, subscribe) the maximum number of signals delivered to new subscribers may potentially be more but this hint provides a general bound for memory when concurrency subsides.ttl- duration each element will be retained before being removed.executor- used to enforce thettlargument.- Returns:
- A
Publisherthat allows for multiple downstream subscribers and emits the previoushistoryHintPublisherSource.Subscriber.onNext(Object)signals to each new subscriber. - See Also:
-
replay
Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut will also retain some history ofPublisherSource.Subscriber.onNext(Object)signals according to theReplayAccumulatoraccumulatorSupplier.- Parameters:
accumulatorSupplier- supplies aReplayAccumulatoron each subscribe to upstream that can retain history ofPublisherSource.Subscriber.onNext(Object)signals to deliver to new downstream subscribers.- Returns:
- A
Publisherthat allows for multiple downstream subscribers that can retain history ofPublisherSource.Subscriber.onNext(Object)signals to deliver to new downstream subscribers. - See Also:
-
replay
Similar tomulticast(int)in that multiple downstreamPublisherSource.Subscribers are enabled on the returnedPublisherbut will also retain some history ofPublisherSource.Subscriber.onNext(Object)signals according to theReplayStrategyreplayStrategy.- Parameters:
replayStrategy- aReplayStrategythat determines the replay behavior and history retention logic.- Returns:
- A
Publisherthat allows for multiple downstream subscribers that can retain history ofPublisherSource.Subscriber.onNext(Object)signals to deliver to new downstream subscribers. - See Also:
-
buffer
public final <BC extends BufferStrategy.Accumulator<T,B>, Publisher<B> bufferB> (BufferStrategy<T, BC, B> strategy) Create aPublisherthat buffers items from thisPublisherand emit those buffers instead of the individual items.In sequential programming this is similar to the following:
Notes:List accumulators = strategy.boundaries(); List buffers = ...; BC currentAccumulator; for (T t : resultOfThisPublisher()) { // This is an approximation; accumulators are emitted asynchronously. BC nextAccumulator = accumulators.remove(0).get(); buffers.add(currentAccumulator.finish()); currentAccumulator = nextAccumulator; currentAccumulator.add(t); } return buffers;- If this
Publisherdoes not emit items within theboundary, it's expected it will emit an emptyaccumulated valueas the result of accumulating nothing. Usefilter(Predicate)operator if empty accumulations have to be discarded. - If more than one
boundaryis emitted while this operatoraccumulatesor emits thenextresult of accumulation, those boundaries will be discarded without invokingBufferStrategy.Accumulator.finish()method.
- Type Parameters:
BC- Type of theBufferStrategy.Accumulatorto buffer items from thisPublisher.B- Type of the buffer emitted from the returnedPublisher.- Parameters:
strategy- ABufferStrategyto use for buffering items from thisPublisher.- Returns:
- a
Publisherthat buffers items from thisPublisherand emit those buffers instead of the individual items. - See Also:
- If this
-
beforeOnSubscribe
public final Publisher<T> beforeOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribeConsumerargument beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher.- Parameters:
onSubscribe- Invoked beforePublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeOnNext
Invokes theonNextConsumerargument beforePublisherSource.Subscriber.onNext(Object)is called forPublisherSource.Subscribers 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeOnError
Invokes theonErrorConsumerargument beforePublisherSource.Subscriber.onError(Throwable)is called forPublisherSource.Subscribers 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeOnComplete
Invokes theonCompleteRunnableargument beforePublisherSource.Subscriber.onComplete()is called forPublisherSource.Subscribers 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeRequest
Invokes theonRequestLongConsumerargument beforePublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher.- Parameters:
onRequest- Invoked beforePublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeCancel
Invokes theonCancelRunnableargument beforeCancellable.cancel()is called forPublisherSource.Subscriptions of the returnedPublisher.- Parameters:
onCancel- Invoked beforeCancellable.cancel()is called forPublisherSource.Subscriptions of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeFinally
Invokes thebeforeFinallyRunnableargument before any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()
PublisherSource.Subscriptions/PublisherSource.Subscribers 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeFinally
Invokes the corresponding method onbeforeFinallyTerminalSignalConsumerargument 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.Subscriptions/PublisherSource.Subscribers 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 thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Publisher. - See Also:
-
beforeSubscriber
public final Publisher<T> beforeSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber(via thesubscriberSupplierargument) on each call to subscribe and invokes all thePublisherSource.Subscribermethods before thePublisherSource.Subscribers of the returnedPublisher.- Parameters:
subscriberSupplier- Creates a newPublisherSource.Subscriberon each call to subscribe and invokes all thePublisherSource.Subscribermethods before thePublisherSource.Subscribers of the returnedPublisher.PublisherSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
beforeSubscription
public final Publisher<T> beforeSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription(via thesubscriptionSupplierargument) on each call to subscribe and invokes all thePublisherSource.Subscriptionmethods before thePublisherSource.Subscriptions of the returnedPublisher.- Parameters:
subscriptionSupplier- Creates a newPublisherSource.Subscriptionon each call to subscribe and invokes all thePublisherSource.Subscriptionmethods before thePublisherSource.Subscriptions of the returnedPublisher.PublisherSource.Subscriptionmethods MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterOnSubscribe
public final Publisher<T> afterOnSubscribe(Consumer<? super PublisherSource.Subscription> onSubscribe) Invokes theonSubscribeConsumerargument afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher.- Parameters:
onSubscribe- Invoked afterPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is called forPublisherSource.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterOnNext
Invokes theonNextConsumerargument afterPublisherSource.Subscriber.onNext(Object)is called forPublisherSource.Subscribers 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterOnError
Invokes theonErrorConsumerargument afterPublisherSource.Subscriber.onError(Throwable)is called forPublisherSource.Subscribers 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterOnComplete
Invokes theonCompleteRunnableargument afterPublisherSource.Subscriber.onComplete()is called forPublisherSource.Subscribers 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.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterRequest
Invokes theonRequestLongConsumerargument afterPublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher.- Parameters:
onRequest- Invoked afterPublisherSource.Subscription.request(long)is called forPublisherSource.Subscriptions of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterCancel
Invokes theonCancelRunnableargument afterCancellable.cancel()is called forPublisherSource.Subscriptions of the returnedPublisher.- Parameters:
onCancel- Invoked afterCancellable.cancel()is called forPublisherSource.Subscriptions of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterFinally
Invokes theafterFinallyRunnableargument after any of the following terminal methods are called:PublisherSource.Subscriber.onComplete()PublisherSource.Subscriber.onError(Throwable)Cancellable.cancel()
PublisherSource.Subscriptions/PublisherSource.Subscribers 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.Subscriptions/PublisherSource.Subscribers of the returnedPublisher. MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
afterFinally
Invokes the corresponding method onafterFinallyTerminalSignalConsumerargument 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.Subscriptions/PublisherSource.Subscribers 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 thisTerminalSignalConsumerwill be invoked.- Returns:
- The new
Publisher. - See Also:
-
afterSubscriber
public final Publisher<T> afterSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes all thePublisherSource.Subscribermethods after thePublisherSource.Subscribers of the returnedPublisher.- Parameters:
subscriberSupplier- Creates a newPublisherSource.Subscriberfor each new subscribe and invokes all thePublisherSource.Subscribermethods after thePublisherSource.Subscribers of the returnedPublisher.PublisherSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenSubscriber
public final Publisher<T> whenSubscriber(Supplier<? extends PublisherSource.Subscriber<? super T>> subscriberSupplier) Creates a newPublisherSource.Subscriber(via thesubscriberSupplierargument) for each new subscribe and invokes methods on thatPublisherSource.Subscriberwhen the corresponding methods are called forPublisherSource.Subscribers of the returnedPublisher.- Parameters:
subscriberSupplier- Creates a newPublisherSource.Subscriberfor each new subscribe and invokes methods on thatPublisherSource.Subscriberwhen the corresponding methods are called forPublisherSource.Subscribers of the returnedPublisher.PublisherSource.Subscribermethods MUST NOT throw.- Returns:
- The new
Publisher.
-
afterSubscription
public final Publisher<T> afterSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription(via thesubscriptionSupplierargument) for each new subscribe and invokes all thePublisherSource.Subscriptionmethods after thePublisherSource.Subscriptions of the returnedPublisher.- Parameters:
subscriptionSupplier- Creates a newPublisherSource.Subscriptionfor each new subscribe and invokes all thePublisherSource.Subscriptionmethods after thePublisherSource.Subscriptions of the returnedPublisher.PublisherSource.Subscriptionmethods MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
whenSubscription
public final Publisher<T> whenSubscription(Supplier<? extends PublisherSource.Subscription> subscriptionSupplier) Creates a newPublisherSource.Subscription(via thesubscriptionSupplierargument) for each new subscribe and invokes all thePublisherSource.Subscriptionmethods when the corresponding methods are called forPublisherSource.Subscriptions of the returnedPublisher.- Parameters:
subscriptionSupplier- Creates a newPublisherSource.Subscriptionfor each new subscribe and invokes all thePublisherSource.Subscriptionmethods when thePublisherSource.Subscriptions of the returnedPublisher.PublisherSource.Subscriptionmethods MUST NOT throw.- Returns:
- The new
Publisher. - See Also:
-
forEach
Subscribes to thisPublisherand invokesforEachConsumerfor each item emitted by thisPublisher.This will request
Long.MAX_VALUEfrom 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-Consumerto invoke for eachPublisherSource.Subscriber.onNext(Object).- Returns:
Cancellableused to invokeCancellable.cancel()on the parameter ofPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)for thisPublisher.
-
publishOn
Creates a newPublisherthat will use the passedExecutorto invoke allPublisherSource.Subscribermethods. This method does not override precedingExecutors, if any, specified forthisPublisher. Only subsequent operations, if any, added in this execution chain will use thisExecutor.Note: unlike
publishOn(io.servicetalk.concurrent.Executor, BooleanSupplier), current operator always enforces offloading to the passedExecutor.- Parameters:
executor-Executorto use.- Returns:
- A new
Publisherthat will use the passedExecutorto invoke allPublisherSource.Subscribermethods. - See Also:
-
publishOn
Creates a newPublisherthat may use the passedExecutorto invoke allPublisherSource.Subscribermethods. This method does not override precedingExecutors, if any, specified forthisPublisher. Only subsequent operations, if any, added in this execution chain will use thisExecutor.Note: unlike
publishOn(io.servicetalk.concurrent.Executor), current operator may skip offloading to the passedExecutor, depending on the result of theBooleanSupplierhint.- Parameters:
executor-Executorto use.shouldOffload- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalseis returned in order to preserve signal ordering.- Returns:
- A new
Publisherthat may use the passedExecutorto invoke allPublisherSource.Subscribermethods. - See Also:
-
subscribeOn
Creates a newPublisherthat will use the passedExecutorto invoke the following methods:- All
PublisherSource.Subscriptionmethods. - The
handleSubscribe(PublisherSource.Subscriber)method.
Executors, if any, specified forthisPublisher. Only subsequent operations, if any, added in this execution chain will use thisExecutor.Note: unlike
subscribeOn(io.servicetalk.concurrent.Executor, BooleanSupplier), current operator always enforces offloading to the passedExecutor.- Parameters:
executor-Executorto use.- Returns:
- A new
Publisherthat will use the passedExecutorto invoke all methods ofPublisherSource.SubscriptionandhandleSubscribe(PublisherSource.Subscriber). - See Also:
- All
-
subscribeOn
Creates a newPublisherthat may use the passedExecutorto invoke the following methods:- All
PublisherSource.Subscriptionmethods. - The
handleSubscribe(PublisherSource.Subscriber)method.
Executors, if any, specified forthisPublisher. Only subsequent operations, if any, added in this execution chain will use thisExecutor.Note: unlike
subscribeOn(io.servicetalk.concurrent.Executor), current operator may skip offloading to the passedExecutor, depending on the result of theBooleanSupplierhint.- Parameters:
executor-Executorto use.shouldOffload- Provides a hint whether offloading to the executor can be omitted or not. Offloading may still occur even iffalseis returned in order to preserve signal ordering.- Returns:
- A new
Publisherthat may use the passedExecutorto invoke all methods ofPublisherSource.SubscriptionandhandleSubscribe(PublisherSource.Subscriber). - See Also:
- All
-
setContextOnSubscribe
Deprecated.requiring this operator is a sign that there is a problem in your operator chain. Usedefer(Supplier)andshareContextOnSubscribe()to control context.Specify theContextMapto use forAsyncContextwhen the returnedPublisheris subscribed to.This operator only impacts behavior if the returned
Publisheris subscribed directly after this operator, that means this must be the "last operator" in the chain for this to have an impact.- Parameters:
context- TheContextMapto use forAsyncContextwhen subscribed.- Returns:
- A
Completablethat will use theContextMapforAsyncContextwhen subscribed.
-
liftSync
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Publisherwhich when subscribed, theoperatorargument will be used to wrap thePublisherSource.Subscriberbefore subscribing to thisPublisher.
ThePublisher<X> pub = ...; pub.map(..) // A .liftSync(original -> modified) .filter(..) // Boriginal -> modified"operator" MUST be "synchronous" in that it does not interact with the originalPublisherSource.Subscriberfrom outside the modifiedPublisherSource.SubscriberorPublisherSource.Subscriptionthreads. That is to say this operator will not impact theExecutorconstraints 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.Subscriberto thisPublisherand the return is the "modified"PublisherSource.Subscriberthat provides custom operator business logic.- Returns:
- a
Publisherwhich when subscribed, theoperatorargument will be used to wrap thePublisherSource.Subscriberbefore subscribing to thisPublisher. - See Also:
-
liftSyncToSingle
public final <R> Single<R> liftSyncToSingle(PublisherToSingleOperator<? super T, ? extends R> operator) This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Singlewhich when subscribed, theoperatorargument will be used to convert between theSingleSource.Subscriberto aPublisherSource.Subscriberbefore 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.Subscriberfrom outside the modifiedPublisherSource.SubscriberorPublisherSource.Subscriptionthreads. That is to say this operator will not impact theExecutorconstraints 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.Subscriberto the returnedSingleand the return is the "modified"PublisherSource.Subscriberthat provides custom operator business logic on thisPublisher.- Returns:
- a
Singlewhich when subscribed, theoperatorargument will be used to convert theSingleSource.Subscriberto aPublisherSource.Subscriberbefore subscribing to thisPublisher.
-
liftAsync
This method requires advanced knowledge of building operators. Before using this method please attempt to compose existing operator(s) to satisfy your use case.Returns a
Publisherwhich will wrap thePublisherSource.Subscriberusing the providedoperatorargument before subscribing to thisPublisher.
ThePublisher<X> pub = ...; pub.map(..) // A .liftAsync(original -> modified) .filter(..) // Boriginal -> modified"operator" MAY be "asynchronous" in that it may interact with the originalPublisherSource.Subscriberfrom outside the modifiedPublisherSource.SubscriberorPublisherSource.Subscriptionthreads. More specifically:- all of the
PublisherSource.Subscriberinvocations going "downstream" (i.e. from A to B above) MAY be offloaded via anExecutor - all of the
PublisherSource.Subscriptioninvocations 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.Subscriberto thisPublisherand the return is the "modified"PublisherSource.Subscriberthat provides custom operator business logic.- Returns:
- a
Publisherwhich when subscribed, theoperatorargument will be used to wrap thePublisherSource.Subscriberbefore subscribing to thisPublisher. - See Also:
- all of the
-
firstOrElse
Converts thisPublisherto aSingle.This operator is useful if the
Publisherthat is being converted is potentially empty (in which case thedefaultValueSupplierwill be triggered) or may emit multiple elements (in which case it will be cancelled after receiving the first element). If a conversion toSingleis needed where it is expected that thePublisherreturns exactly one element, consider usingfirstOrError()instead.- Parameters:
defaultValueSupplier- ASupplierof default value if thisPublisherdid not emit any item.- Returns:
- A
Singlethat will contain the first item emitted from the thisPublisher. If the sourcePublisherdoes not emit any item, then the returnedSinglewill contain the value as returned by the passedSupplier. - See Also:
-
firstOrError
Converts thisPublisherto aSingleand ensures that it emits exactly a singleelementbefore completion.This operator ensures that the
Publisheremits exactly a singlePublisherSource.Subscriber.onNext(Object)to itsPublisherSource.Subscriber. If thisPublisherterminates without emitting any items aNoSuchElementExceptionwill be signaled and if thisPublisheremits more than one item, anIllegalArgumentExceptionwill be signaled. Any error emitted by thisPublisherwill be forwarded to the returnedSingle.To uphold the guarantees laid out in the previous paragraph, this operator requests two items from the
Publisher. This means that if thePublisherdoes not complete after signaling one element, this operator will not complete. If "one element and then complete" semantics are desired, consider chaining thetakeAtMost(1)operator beforehand. This will ensure a completion signal after one item is propagated from thePublisher.- Returns:
- A
Singlethat will contain the first item emitted from the thisPublisher. If the sourcePublisherdoes not emit any item, then the returnedSinglewill terminate withNoSuchElementException. - See Also:
-
ignoreElements
Ignores all elements emitted by thisPublisherand forwards the termination signal to the returnedCompletable.- Returns:
- A
Completablethat mirrors the terminal signal from thisPublisher. - See Also:
-
completableOrError
Converts thisPublisherto aCompletable. If thisPublisheremits anyPublisherSource.Subscriber.onNext(Object)signals the resultingCompletablewill be terminated with aIllegalArgumentException.- Returns:
- A
Completablethat mirrors the terminal signal from thisPublisher, and terminates in error if anPublisherSource.Subscriber.onNext(Object)signals.
-
collect
public final <R> Single<R> collect(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> collector) Collects all items emitted by thisPublisherinto 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 returnedSingleis subscribed.collector- Invoked for every item emitted by the sourcePublisherand returns the same or alteredresultobject.- Returns:
- A
Singlethat completes with the singleresultor any error emitted by the sourcePublisher. - See Also:
-
toFuture
Convert thisPublisherinto aFuturewith aCollectioncontaining the elements of thisPublisherupon successful termination. If thisPublisherterminates in an error, then the intermediateCollectionwill be discarded and theFuturewill complete exceptionally.- Returns:
- a
Futurewith aCollectioncontaining the elements of thisPublisherupon successful termination. - See Also:
-
toFuture
public final <R> Future<R> toFuture(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) Convert thisPublisherinto aFutureof typePublisherwhich represents all elements of thisPublisherupon successful termination. If thisPublisherterminates in an error, then the intermediatePublisherwill be discarded and theFuturewill 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 sourcePublisherand returns the same or alteredresultobject.- Returns:
- a
Futureof typePublisherwhich represents all elements of thisPublisherupon successful termination.
-
toCompletionStage
Convert thisPublisherinto aCompletionStagewith aCollectioncontaining the elements of thisPublisherupon successful termination. If thisPublisherterminates in an error, then the intermediateCollectionwill be discarded and theCompletionStagewill complete exceptionally.- Returns:
- a
CompletionStagewith aCollectioncontaining the elements of thisPublisherupon successful termination. - See Also:
-
toCompletionStage
public final <R> CompletionStage<R> toCompletionStage(Supplier<? extends R> resultFactory, BiFunction<? super R, ? super T, R> reducer) Convert thisPublisherinto aCompletionStageof typePublisherwhich represents all elements of thisPublisherupon successful termination. If thisPublisherterminates in an error, then the intermediatePublisherwill be discarded and theCompletionStagewill 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 sourcePublisherand returns the same or alteredresultobject.- Returns:
- a
CompletionStageof typePublisherwhich represents all elements of thisPublisherupon successful termination.
-
toInputStream
Subscribes tothisPublisherand converts all signals received by thePublisherSource.Subscriberto the returnedInputStreamfollowing the below rules:PublisherSource.Subscriptionreceived byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is used to request more data when required. If the returnedInputStreamis closed,PublisherSource.Subscriptionis cancelled and any unread data is disposed.- Any items received by
PublisherSource.Subscriber.onNext(Object)are converted to abyte[]using the passedserializer. Thesebytes are available to be read from theInputStream - Any
Throwablereceived 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-1to indicate end of stream after emitting all received data.
Flow control
This operator may pre-fetch may pre-fetch items fromthisPublisherif available to reduce blocking for read operations from the returnedInputStream. In order to increase responsiveness of theInputStreamsome amount of buffering may be done. UsetoInputStream(Function, int)to manage capacity of this buffer.- Parameters:
serializer-Functionthat is invoked for every item emitted bythisPublisher.- Returns:
InputStreamthat emits all data emitted bythisPublisher. IfthisPublisherterminates with an error, same error is thrown (wrapped in anIOException) from the returnedInputStreams read methods after emitting all received data.
-
toInputStream
Subscribes tothisPublisherand converts all signals received by thePublisherSource.Subscriberto the returnedInputStreamfollowing the below rules:PublisherSource.Subscriptionreceived byPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)is used to request more data when required. If the returnedInputStreamis closed,PublisherSource.Subscriptionis cancelled and any unread data is disposed.- Any items received by
PublisherSource.Subscriber.onNext(Object)are converted to abyte[]using the passedserializer. Thesebytes are available to be read from theInputStream - Any
Throwablereceived 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-1to indicate end of stream after emitting all received data.
Flow control
This operator may pre-fetch items fromthisPublisherif available to reduce blocking for read operations from the returnedInputStream. In order to increase responsiveness of theInputStreamsome amount of buffering may be done.queueCapacitycan be used to bound this buffer.- Parameters:
serializer-Functionthat is invoked for every item emitted bythisPublisher.queueCapacity- Hint for the capacity of the intermediary queue that stores items that are emitted bythisPublisherbut has not yet been read from the returnedInputStream.- Returns:
InputStreamthat emits all data emitted bythisPublisher. IfthisPublisherterminates with an error, same error is thrown (wrapped in anIOException) from the returnedInputStreams read methods after emitting all received data.
-
toIterable
ConvertsthisPublisherto anBlockingIterable. Every timeBlockingIterable.iterator()is called on the returnedBlockingIterable,thisPublisheris subscribed following the below rules:PublisherSource.Subscriptionreceived 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
Throwablereceived byPublisherSource.Subscriber.onError(Throwable)is thrown (wrapped in aRuntimeExceptionif required) whenBlockingIterator.next()is called. This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()is called, returnedBlockingIteratorsIterator.hasNext()will returnfalseBlockingIterator.next()will throwNoSuchElementException. This error will be thrown only after draining all queued data, if any.
Flow control
This operator may pre-fetch items fromthisPublisherif available to reduce blocking ofIterator.hasNext()from the returnedBlockingIterable. In order to increase responsiveness of theIteratorsome amount of buffering may be done. UsetoIterable(int)to manage capacity of this buffer.Blocking
The returnedBlockingIteratorfrom the returnedBlockingIterablewill 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:
BlockingIterablerepresentingthisPublisher. Every timeBlockingIterable.iterator()is invoked on theBlockingIterable,thisPublisheris subscribed.BlockingIterators returned from thisBlockingIterabledo not supportIterator.remove().
-
toIterable
ConvertsthisPublisherto anBlockingIterable. Every timeBlockingIterable.iterator()is called on the returnedBlockingIterable,thisPublisheris subscribed following the below rules:PublisherSource.Subscriptionreceived 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
Throwablereceived byPublisherSource.Subscriber.onError(Throwable)is thrown (wrapped in aRuntimeExceptionif required) whenBlockingIterator.next(). This error will be thrown only after draining all queued data, if any. - When
PublisherSource.Subscriber.onComplete()is called, returnedBlockingIteratorsIterator.hasNext()will returnfalseandBlockingIterator.next()will throwNoSuchElementException. This error will be thrown only after draining all queued data, if any.
Flow control
This operator may pre-fetch items fromthisPublisherif available to reduce blocking ofIterator.hasNext()from the returnedBlockingIterable. In order to increase responsiveness of theBlockingIteratorsome amount of buffering may be done.queueCapacityHintcan be used to bound this buffer.Blocking
The returnedBlockingIteratorfrom the returnedBlockingIterablewill 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 bythisPublisherbut has not yet been returned from theBlockingIterator.- Returns:
BlockingIterablerepresentingthisPublisher. Every timeBlockingIterable.iterator()is invoked on theBlockingIterable,thisPublisheris subscribed.BlockingIterators returned from thisBlockingIterabledo not supportIterator.remove().
-
subscribeInternal
A internal subscribe method similar toPublisherSource.subscribe(Subscriber)which can be used by different implementations to subscribe.- Parameters:
subscriber-PublisherSource.Subscriberto subscribe for the result.
-
handleSubscribe
Handles a subscriber to thisPublisher.- Parameters:
subscriber- the subscriber.
-
from
Creates a newPublisherthat emitsvalueto itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
value- Value that the returnedPublisherwill emit.- Returns:
- A new
Publisherthat emitsvalueto itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete(). - See Also:
-
from
Creates a newPublisherthat emitsv1andv2to itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
v1- The first value that the returnedPublisherwill emit.v2- The second value that the returnedPublisherwill emit.- Returns:
- A new
Publisherthat emitsv1andv2to itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete(). - See Also:
-
from
Creates a newPublisherthat emitsv1,v2, andv3to itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
v1- The first value that the returnedPublisherwill emit.v2- The second value that the returnedPublisherwill emit.v3- The third value that the returnedPublisherwill emit.- Returns:
- A new
Publisherthat emitsv1,v2, andv3to itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete(). - See Also:
-
from
Creates a newPublisherthat emits allvaluesto itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
values- Values that the returnedPublisherwill emit.- Returns:
- A new
Publisherthat emits allvaluesto itsPublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete(). - See Also:
-
fromIterable
Create a newPublisherthat when subscribed will get anIteratorviaIterable.iterator()and emit all values to thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscriptionshould be "responsive". The responsiveness of the associatedPublisherSource.Subscriptions will depend upon the behavior of theiterablebelow. Make sure theExecutorfor 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 ofIteratorto extract data from.Iterable.iterator()must not returnnull. If this is of typeBlockingIterablethen any generatedBlockingIterators will have theirBlockingIterator.close()method called if an error occurs.- Returns:
- a new
Publisherthat when subscribed will get anIteratorviaIterable.iterator()and emit all values to thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().
-
fromBlockingIterable
public static <T> Publisher<T> fromBlockingIterable(BlockingIterable<? extends T> iterable, LongSupplier timeoutSupplier, TimeUnit unit) Create a newPublisherthat when subscribed will get aBlockingIteratorviaBlockingIterable.iterator()and emit all values to thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscriptionshould be "responsive". The responsiveness of the associatedPublisherSource.Subscriptions will depend upon the behavior of theiterablebelow. Make sure theExecutorfor 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 ofIteratorto extract data from.Iterable.iterator()must not returnnull. Any generatedBlockingIterators will have theirBlockingIterator.close()method called if an error occurs.timeoutSupplier- ALongSupplierwhich provides the time duration to wait for each interaction withiterable.unit- The time units for thetimeoutduration.- Returns:
- a new
Publisherthat when subscribed will get aBlockingIteratorviaBlockingIterable.iterator()and emit all values to thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().
-
fromInputStream
Deprecated.Create a newPublisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().The resulting publisher is not replayable and supports only a single
PublisherSource.Subscriber.After a returned
Publisheris subscribed, it owns the passedInputStream, meaning that theInputStreamwill be automatically closed when thePublisheris cancelled or terminated. Not necessary to close theInputStreamafter subscribe, but it should be closed when control flow never subscribes to the returnedPublisher.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscriptionshould be "responsive". The responsiveness of the associatedPublisherSource.Subscriptions will depend upon the behavior of thestreambelow. Make sure theExecutorfor 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.Subscriberby the returnedPublisher. Given the blocking nature ofInputStream, assumePublisherSource.Subscription.request(long)can block when the underlyingInputStreamblocks onInputStream.read(byte[], int, int).- Returns:
- a new
Publisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().
-
fromInputStream
Deprecated.Create a newPublisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().The resulting publisher is not replayable and supports only a single
PublisherSource.Subscriber.After a returned
Publisheris subscribed, it owns the passedInputStream, meaning that theInputStreamwill be automatically closed when thePublisheris cancelled or terminated. Not necessary to close theInputStreamafter subscribe, but it should be closed when control flow never subscribes to the returnedPublisher.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscriptionshould be "responsive". The responsiveness of the associatedPublisherSource.Subscriptions will depend upon the behavior of thestreambelow. Make sure theExecutorfor 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.Subscriberby the returnedPublisher. Given the blocking nature ofInputStream, assumePublisherSource.Subscription.request(long)can block when the underlyingInputStreamblocks onInputStream.read(byte[], int, int).readChunkSize- the maximum length ofbyte[]chunks which will be read from theInputStreamand emitted by the returnedPublisher.- Returns:
- a new
Publisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberand thenPublisherSource.Subscriber.onComplete().
-
fromInputStream
Create a newPublisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberas a mapped typeTand thenPublisherSource.Subscriber.onComplete().The resulting publisher is not replayable and supports only a single
PublisherSource.Subscriber.After a returned
Publisheris subscribed, it owns the passedInputStream, meaning that theInputStreamwill be automatically closed when thePublisheris cancelled or terminated. Not necessary to close theInputStreamafter subscribe, but it should be closed when control flow never subscribes to the returnedPublisher.The Reactive Streams specification provides two criteria ( 3.4, and 3.5) stating the
PublisherSource.Subscriptionshould be "responsive". The responsiveness of the associatedPublisherSource.Subscriptions will depend upon the behavior of thestreambelow. Make sure theExecutorfor this execution chain can tolerate this responsiveness and any blocking behavior.Given the blocking nature of
InputStream, assumePublisherSource.Subscription.request(long)can block when the underlyingInputStreamblocks onInputStream.read(byte[], int, int).- Type Parameters:
T- Type of the items emitted by the returnedPublisher.- Parameters:
stream- provides the data in the form ofbyte[]buffer regions for the specifiedByteArrayMapper.mapper- a mapper to transform rawbyte[]buffer regions into a desired typeTto be emitted to thePublisherSource.Subscriberby the returnedPublisher.- Returns:
- a new
Publisherthat when subscribed will emit all data from theInputStreamto thePublisherSource.Subscriberas a mapped typeTand thenPublisherSource.Subscriber.onComplete().
-
range
-
range
Create a newPublisherthat when subscribed will emit allIntegers within the range of [begin,end) with an increment ofstridebetween 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
Publisherthat when subscribed will emit allIntegers within the range of [begin,end) with an increment ofstridebetween each signal. - See Also:
-
empty
Creates a newPublisherthat completes when subscribed without emitting any item to itsPublisherSource.Subscriber.- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Returns:
- A new
Publisherthat completes when subscribed without emitting any item to itsPublisherSource.Subscriber. - See Also:
-
never
Creates a newPublisherthat never emits any item to itsPublisherSource.Subscriberand never call any terminal methods on it.- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Returns:
- A new
Publisherthat never emits any item to itsPublisherSource.Subscriberand never call any terminal methods on it. - See Also:
-
failed
Creates a newPublisherthat terminates itsPublisherSource.Subscriberwith an error without emitting any item to it.- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
cause- TheThrowablethat is used to terminate thePublisherSource.Subscriber.- Returns:
- A new
Publisherthat terminates itsPublisherSource.Subscriberwith an error without emitting any item to it. - See Also:
-
defer
Defers creation of aPublishertill it is subscribed.- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
publisherSupplier-Supplierto create a newPublisherevery time the returnedPublisheris subscribed.- Returns:
- A new
Publisherthat creates a newPublisherusingpublisherSupplierevery time it is subscribed and forwards all items and terminal events from the newly createdPublisherto itsPublisherSource.Subscriber. - See Also:
-
mergeAll
Merge allPublishers together. There is no guaranteed ordering of events emitted from the returnedPublisher.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. } return mergedResults; -
mergeAll
@SafeVarargs public static <T> Publisher<T> mergeAll(int maxConcurrency, Publisher<? extends T>... publishers) Merge allPublishers together. There is no guaranteed ordering of events emitted from the returnedPublisher.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (Future<R> future : futures) { future.get(); // Throws if the processing for this item failed. } return mergedResults;- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
maxConcurrency- The maximum amount ofPublishers frompublishersto subscribe to concurrently.publishers- ThePublishers to merge together.- Returns:
- A
Publisherwhich is the result of thisPublisherandothermerged together. - See Also:
-
mergeAllDelayError
@SafeVarargs public static <T> Publisher<T> mergeAllDelayError(Publisher<? extends T>... publishers) Merge allPublishers together. There is no guaranteed ordering of events emitted from the returnedPublisher. If anyPublisherterminates in an error, the error propagation will be delayed until all terminate.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); return mergedResults; -
mergeAllDelayError
@SafeVarargs public static <T> Publisher<T> mergeAllDelayError(int maxConcurrency, Publisher<? extends T>... publishers) Merge allPublishers together. There is no guaranteed ordering of events emitted from the returnedPublisher. If anyPublisherterminates in an error, the error propagation will be delayed until all terminate.This method provides similar capabilities as expanding each result into a collection and concatenating each collection in sequential programming:
List<T> mergedResults = ...; // concurrent safe list for (T t : resultOfPublisher1()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } for (T t : resultOfOtherPublisher()) { futures.add(e.submit(() -> { return mergedResults.add(t); })); } List<Throwable> errors = ...; for (Future<R> future : futures) { try { future.get(); // Throws if the processing for this item failed. } catch (Throwable cause) { errors.add(cause); } } throwExceptionIfNotEmpty(errors); return mergedResults;- Type Parameters:
T- Type of items emitted by the returnedPublisher.- Parameters:
maxConcurrency- The maximum amount ofPublishers frompublishersto subscribe to concurrently.publishers- ThePublishers to merge together.- Returns:
- A
Publisherwhich is the result of thisPublisherandothermerged together. - See Also:
-
fromInputStream(InputStream, ByteArrayMapper)withByteArrayMapper.toByteArray().