Class Flowables
- java.lang.Object
-
- hu.akarnokd.rxjava3.operators.Flowables
-
public final class Flowables extends java.lang.ObjectUtility class to create Flowable sources.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,S>
Flowable<T>generateAsync(Supplier<S> initialState, BiFunction<S,FlowableAsyncEmitter<T>,S> asyncGenerator, Consumer<? super S> stateCleanup)Generates items by invoking a callback, for each downstream request one by one, that sets up an asynchronous call to some API that eventually responds with an item, an error or termination, while making sure there is only one such outstanding API call in progress and honoring the backpressure of the downstream.static Flowable<java.lang.Long>intervalBackpressure(long initialDelay, long period, java.util.concurrent.TimeUnit unit)Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.static Flowable<java.lang.Long>intervalBackpressure(long initialDelay, long period, java.util.concurrent.TimeUnit unit, Scheduler scheduler)Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.static Flowable<java.lang.Long>intervalBackpressure(long period, java.util.concurrent.TimeUnit unit)Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.static Flowable<java.lang.Long>intervalBackpressure(long period, java.util.concurrent.TimeUnit unit, Scheduler scheduler)Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.static <T extends java.lang.Comparable<? super T>>
Flowable<T>orderedMerge(boolean delayErrors, int prefetch, Publisher<T>... sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.static <T extends java.lang.Comparable<? super T>>
Flowable<T>orderedMerge(boolean delayErrors, Publisher<T>... sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order) and allows delaying any error they may signal.static <T extends java.lang.Comparable<? super T>>
Flowable<T>orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order).static <T extends java.lang.Comparable<? super T>>
Flowable<T>orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, boolean delayErrors)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order) and allows delaying any error they may signal.static <T extends java.lang.Comparable<? super T>>
Flowable<T>orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, boolean delayErrors, int prefetch)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.static <T> Flowable<T>orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, java.util.Comparator<? super T> comparator)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator).static <T> Flowable<T>orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, java.util.Comparator<? super T> comparator, boolean delayErrors)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator) and allows delaying any error they may signal.static <T> Flowable<T>orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, java.util.Comparator<? super T> comparator, boolean delayErrors, int prefetch)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.static <T> Flowable<T>orderedMerge(java.util.Comparator<? super T> comparator, boolean delayErrors, int prefetch, Publisher<T>... sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.static <T> Flowable<T>orderedMerge(java.util.Comparator<? super T> comparator, boolean delayErrors, Publisher<T>... sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator) and allows delaying any error they may signal.static <T> Flowable<T>orderedMerge(java.util.Comparator<? super T> comparator, Publisher<T>... sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator).static <T extends java.lang.Comparable<? super T>>
Flowable<T>orderedMerge(Publisher<T>... sources)Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order).static <T> Flowable<T>repeat(T item)Repeats a scalar value indefinitely.static <T> Flowable<T>repeatSupplier(Supplier<T> supplier)Repeatedly calls the given Supplier to produce items indefinitely.static <T,R>
Flowable<R>zipLatest(Function<? super java.lang.Object[],? extends R> combiner, Scheduler scheduler, Publisher<? extends T>... sources)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T,R>
Flowable<R>zipLatest(Function<? super java.lang.Object[],? extends R> combiner, Publisher<? extends T>... sources)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T,R>
Flowable<R>zipLatest(java.lang.Iterable<? extends Publisher<? extends T>> sources, Function<? super java.lang.Object[],? extends R> combiner)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T,R>
Flowable<R>zipLatest(java.lang.Iterable<? extends Publisher<? extends T>> sources, Function<? super java.lang.Object[],? extends R> combiner, Scheduler scheduler)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T1,T2,R>
Flowable<R>zipLatest(Publisher<T1> source1, Publisher<T2> source2, BiFunction<? super T1,? super T2,? extends R> combiner)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T1,T2,R>
Flowable<R>zipLatest(Publisher<T1> source1, Publisher<T2> source2, BiFunction<? super T1,? super T2,? extends R> combiner, Scheduler scheduler)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T1,T2,T3,R>
Flowable<R>zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Function3<? super T1,? super T2,? super T3,? extends R> combiner)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T1,T2,T3,R>
Flowable<R>zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Function3<? super T1,? super T2,? super T3,? extends R> combiner, Scheduler scheduler)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T1,T2,T3,T4,R>
Flowable<R>zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Publisher<T4> source4, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.static <T1,T2,T3,T4,R>
Flowable<R>zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Publisher<T4> source4, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner, Scheduler scheduler)Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.
-
-
-
Method Detail
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <T extends java.lang.Comparable<? super T>> Flowable<T> orderedMerge(Publisher<T>... sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order).- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sources- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <T extends java.lang.Comparable<? super T>> Flowable<T> orderedMerge(boolean delayErrors, Publisher<T>... sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order) and allows delaying any error they may signal.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcesdelayErrors- if true, source errors are delayed until all sources terminate in some way- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <T extends java.lang.Comparable<? super T>> Flowable<T> orderedMerge(boolean delayErrors, int prefetch, Publisher<T>... sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcesdelayErrors- if true, source errors are delayed until all sources terminate in some wayprefetch- the number of items to prefetch from the sources- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <T> Flowable<T> orderedMerge(java.util.Comparator<? super T> comparator, Publisher<T>... sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator).- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcescomparator- the comparator to use for comparing items; it is called with the last known smallest in its first argument- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <T> Flowable<T> orderedMerge(java.util.Comparator<? super T> comparator, boolean delayErrors, Publisher<T>... sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator) and allows delaying any error they may signal.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcescomparator- the comparator to use for comparing items; it is called with the last known smallest in its first argumentdelayErrors- if true, source errors are delayed until all sources terminate in some way- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") @SafeVarargs public static <T> Flowable<T> orderedMerge(java.util.Comparator<? super T> comparator, boolean delayErrors, int prefetch, Publisher<T>... sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcescomparator- the comparator to use for comparing items; it is called with the last known smallest in its first argumentdelayErrors- if true, source errors are delayed until all sources terminate in some wayprefetch- the number of items to prefetch from the sources- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T> Flowable<T> orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, java.util.Comparator<? super T> comparator)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator).- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcescomparator- the comparator to use for comparing items; it is called with the last known smallest in its first argument- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T> Flowable<T> orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, java.util.Comparator<? super T> comparator, boolean delayErrors)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator) and allows delaying any error they may signal.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcescomparator- the comparator to use for comparing items; it is called with the last known smallest in its first argumentdelayErrors- if true, source errors are delayed until all sources terminate in some way- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T> Flowable<T> orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, java.util.Comparator<? super T> comparator, boolean delayErrors, int prefetch)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by the Comparator), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcescomparator- the comparator to use for comparing items; it is called with the last known smallest in its first argumentdelayErrors- if true, source errors are delayed until all sources terminate in some wayprefetch- the number of items to prefetch from the sources- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T extends java.lang.Comparable<? super T>> Flowable<T> orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order).- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sources- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T extends java.lang.Comparable<? super T>> Flowable<T> orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, boolean delayErrors)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order) and allows delaying any error they may signal.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcesdelayErrors- if true, source errors are delayed until all sources terminate in some way- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
orderedMerge
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T extends java.lang.Comparable<? super T>> Flowable<T> orderedMerge(java.lang.Iterable<? extends Publisher<T>> sources, boolean delayErrors, int prefetch)
Merges the source Publishers in an ordered fashion picking the smallest of the available value from them (determined by their natural order), allows delaying any error they may signal and sets the prefetch amount when requesting from these Publishers.- Type Parameters:
T- the value type of all sources- Parameters:
sources- the iterable sequence of sourcesdelayErrors- if true, source errors are delayed until all sources terminate in some wayprefetch- the number of items to prefetch from the sources- Returns:
- the new Flowable instance
- Since:
- 0.8.0
-
repeat
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T> Flowable<T> repeat(T item)
Repeats a scalar value indefinitely.- Type Parameters:
T- the value type- Parameters:
item- the value to repeat- Returns:
- the new Flowable instance
- Since:
- 0.14.2
-
repeatSupplier
@BackpressureSupport(FULL) @SchedulerSupport("none") public static <T> Flowable<T> repeatSupplier(Supplier<T> supplier)
Repeatedly calls the given Supplier to produce items indefinitely.- Type Parameters:
T- the value type- Parameters:
supplier- the Supplier to call- Returns:
- the new Flowable instance
- Since:
- 0.14.2
-
intervalBackpressure
@BackpressureSupport(FULL) @SchedulerSupport("io.reactivex:computation") public static Flowable<java.lang.Long> intervalBackpressure(long period, java.util.concurrent.TimeUnit unit)
Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.- Backpressure:
- The operator honors the backpressure of the downstream and no emission is lost, however, the timing of the reception of the values is now dependent on the downstream backpressure.
- Scheduler:
- The operator uses the
computationSchedulerto time the emission and likely deliver the value (unless backpressured).
- Parameters:
period- the emission period (including the delay for the first emission)unit- the emission time unit- Returns:
- the new Flowable instance
- Since:
- 0.15.0
-
intervalBackpressure
@BackpressureSupport(FULL) @SchedulerSupport("custom") public static Flowable<java.lang.Long> intervalBackpressure(long period, java.util.concurrent.TimeUnit unit, Scheduler scheduler)
Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.- Backpressure:
- The operator honors the backpressure of the downstream and no emission is lost, however, the timing of the reception of the values is now dependent on the downstream backpressure.
- Scheduler:
- The operator uses the
computationSchedulerto time the emission and likely deliver the value (unless backpressured).
- Parameters:
period- the emission period (including the delay for the first emission)unit- the emission time unitscheduler- the scheduler to use for timing and likely emitting items- Returns:
- the new Flowable instance
- Since:
- 0.15.0
-
intervalBackpressure
@BackpressureSupport(FULL) @SchedulerSupport("io.reactivex:computation") public static Flowable<java.lang.Long> intervalBackpressure(long initialDelay, long period, java.util.concurrent.TimeUnit unit)
Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.- Backpressure:
- The operator honors the backpressure of the downstream and no emission is lost, however, the timing of the reception of the values is now dependent on the downstream backpressure.
- Scheduler:
- The operator uses the
computationSchedulerto time the emission and likely deliver the value (unless backpressured).
- Parameters:
initialDelay- the initial delay before emitting the first 0Lperiod- the emission period after the first emissionunit- the emission time unit- Returns:
- the new Flowable instance
- Since:
- 0.15.0
-
intervalBackpressure
@BackpressureSupport(FULL) @SchedulerSupport("custom") public static Flowable<java.lang.Long> intervalBackpressure(long initialDelay, long period, java.util.concurrent.TimeUnit unit, Scheduler scheduler)
Periodically tries to emit an ever increasing long value or buffers (efficiently) such emissions until the downstream requests.- Backpressure:
- The operator honors the backpressure of the downstream and no emission is lost, however, the timing of the reception of the values is now dependent on the downstream backpressure.
- Scheduler:
- The operator uses the
Schedulerprovided to time the emission and likely deliver the value (unless backpressured).
- Parameters:
initialDelay- the initial delay before emitting the first 0Lperiod- the emission period (including the delay for the first emission)unit- the emission time unitscheduler- the scheduler to use for timing and likely emitting items- Returns:
- the new Flowable instance
- Since:
- 0.15.0
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("none") @SafeVarargs public static <T,R> Flowable<R> zipLatest(Function<? super java.lang.Object[],? extends R> combiner, Publisher<? extends T>... sources)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator doesn't run on any particular
Schedulerand the combined item emission happens on the thread that won the internal emission-right race.
- Type Parameters:
T- the common source value typeR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.sources- the array of source Publishers to zip/combine- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("custom") @SafeVarargs public static <T,R> Flowable<R> zipLatest(Function<? super java.lang.Object[],? extends R> combiner, Scheduler scheduler, Publisher<? extends T>... sources)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator emits the combined items on the
Schedulerprovided.
- Type Parameters:
T- the common source value typeR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.sources- the array of source Publishers to zip/combinescheduler- the Scheduler to use for emitting items and/or terminal signals- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("none") public static <T,R> Flowable<R> zipLatest(java.lang.Iterable<? extends Publisher<? extends T>> sources, Function<? super java.lang.Object[],? extends R> combiner)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator doesn't run on any particular
Schedulerscheduler and the combined item emission happens on the thread that won the internal emission-right race.
- Type Parameters:
T- the common source value typeR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.sources- the array of source Publishers to zip/combine- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("custom") public static <T,R> Flowable<R> zipLatest(java.lang.Iterable<? extends Publisher<? extends T>> sources, Function<? super java.lang.Object[],? extends R> combiner, Scheduler scheduler)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator emits the combined items on the
Schedulerprovided.
- Type Parameters:
T- the common source value typeR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.sources- the array of source Publishers to zip/combinescheduler- the Scheduler to use for emitting items and/or terminal signals- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("none") public static <T1,T2,R> Flowable<R> zipLatest(Publisher<T1> source1, Publisher<T2> source2, BiFunction<? super T1,? super T2,? extends R> combiner)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator doesn't run on any particular
Schedulerscheduler and the combined item emission happens on the thread that won the internal emission-right race.
- Type Parameters:
T1- the value type of the first source PublisherT2- the value type of the second source PublisherR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.source1- the first source Publisher instancesource2- the second source Publisher instance- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("custom") public static <T1,T2,R> Flowable<R> zipLatest(Publisher<T1> source1, Publisher<T2> source2, BiFunction<? super T1,? super T2,? extends R> combiner, Scheduler scheduler)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator emits the combined items on the
Schedulerprovided.
- Type Parameters:
T1- the value type of the first source PublisherT2- the value type of the second source PublisherR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.source1- the first source Publisher instancesource2- the second source Publisher instancescheduler- the Scheduler to use for emitting items and/or terminal signals- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("none") public static <T1,T2,T3,R> Flowable<R> zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Function3<? super T1,? super T2,? super T3,? extends R> combiner)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator doesn't run on any particular
Schedulerscheduler and the combined item emission happens on the thread that won the internal emission-right race.
- Type Parameters:
T1- the value type of the first source PublisherT2- the value type of the second source PublisherT3- the value type of the third source PublisherR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.source1- the first source Publisher instancesource2- the second source Publisher instancesource3- the third source Publisher instance- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("custom") public static <T1,T2,T3,R> Flowable<R> zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Function3<? super T1,? super T2,? super T3,? extends R> combiner, Scheduler scheduler)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator emits the combined items on the
Schedulerprovided.
- Type Parameters:
T1- the value type of the first source PublisherT2- the value type of the second source PublisherT3- the value type of the third source PublisherR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.source1- the first source Publisher instancesource2- the second source Publisher instancesource3- the third source Publisher instancescheduler- the Scheduler to use for emitting items and/or terminal signals- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("none") public static <T1,T2,T3,T4,R> Flowable<R> zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Publisher<T4> source4, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator doesn't run on any particular
Schedulerscheduler and the combined item emission happens on the thread that won the internal emission-right race.
- Type Parameters:
T1- the value type of the first source PublisherT2- the value type of the second source PublisherT3- the value type of the third source PublisherT4- the value type of the fourth source PublisherR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.source1- the first source Publisher instancesource2- the second source Publisher instancesource3- the third source Publisher instancesource4- the fourth source Publisher instance- Returns:
- the new Flowable instance.
-
zipLatest
@BackpressureSupport(UNBOUNDED_IN) @SchedulerSupport("custom") public static <T1,T2,T3,T4,R> Flowable<R> zipLatest(Publisher<T1> source1, Publisher<T2> source2, Publisher<T3> source3, Publisher<T4> source4, Function4<? super T1,? super T2,? super T3,? super T4,? extends R> combiner, Scheduler scheduler)
Zips the latest available values of the source Publishers via a combiner function where the emission rate is determined by the slowest Publisher and the downstream consumption rate.Non-consumed source values are overwritten by newer values. Unlike
combineLatest, source values are not reused to form new combinations.If any of the sources runs out of items, the other sources are cancelled and the sequence completes.
A: ---o-o-o------o-o----o---o-|------- B: ---------x-x--x-------x-----x--x--- ======= zipLatest (o, x -> M) ======== R: ---------M----M-------M-----M|------ Backpressure:
- The operator honors the backpressure of the downstream and consumes the source Publishers in an unbounded manner, keeping only their latest values temporarily.
- Scheduler:
- The operator emits the combined items on the
Schedulerprovided.
- Type Parameters:
T1- the value type of the first source PublisherT2- the value type of the second source PublisherT3- the value type of the third source PublisherT4- the value type of the fourth source PublisherR- the result type- Parameters:
combiner- the function receiving the latest values of the sources and returns a value to be emitted to the downstream.source1- the first source Publisher instancesource2- the second source Publisher instancesource3- the third source Publisher instancesource4- the fourth source Publisher instancescheduler- the Scheduler to use for emitting items and/or terminal signals- Returns:
- the new Flowable instance.
-
generateAsync
@CheckReturnValue @BackpressureSupport(FULL) @SchedulerSupport("none") public static <T,S> Flowable<T> generateAsync(Supplier<S> initialState, BiFunction<S,FlowableAsyncEmitter<T>,S> asyncGenerator, Consumer<? super S> stateCleanup)
Generates items by invoking a callback, for each downstream request one by one, that sets up an asynchronous call to some API that eventually responds with an item, an error or termination, while making sure there is only one such outstanding API call in progress and honoring the backpressure of the downstream.This operator allows the bridging of the asynchronous and backpressurable world with the reactive world, where backpressure is the emergent effect of making sure there is only one outstanding API call at a time which responds with at most one item per invocation.
Note that the implementation may have one outstanding API call even if the downstream hasn't requested more and as such, the resulting item may get cached until the downstream requests for more.
During the async response, the invocation protocol of the
FlowableAsyncEmittershould be as follows:
In words, an(onNext | onNothing)? (onError | onComplete)?onNextoronNothing(which indicates this particular API call resulted in no items and the next API call can proceed) may be followed by a terminal event.The methods
Emitter.onNext(Object),Emitter.onError(Throwable),Emitter.onComplete()andFlowableAsyncEmitter.onNothing()should not be called concurrently with each other or outside the context of the generator. The rest of theFlowableAsyncEmittermethods are thread-safe.Example:
Let's assume there is an async API with the following interface definition:
When the call succeeds, theinterface AsyncAPI<T> extends AutoCloseable { CompletableFuture<Void> nextValue(Consumer<? super T> onValue); }onValueis invoked with it. If there are no more items, theCompletableFuturereturned by the lastnextValueis completed (with null). If there is an error, the sameCompletableFutureis completed exceptionally. EachnextValueinvocation creates a freshCompletableFuturewhich can be cancelled if necesary.nextValueshould not be invoked again until theonValuecallback has been notified.
An instance of this API can be obtained on demand, thus the state of this operator consists of theAsyncAPIinstance supplied for each individualSubscriber. The API can be transformed into aFlowableas follows:Flowable<Integer> source = Flowable.<Integer, AsyncAPI<Integer>>generateAsync( // create a fresh API instance for each individual Subscriber () -> new AsyncAPIImpl<Integer>(), // this BiFunction will be called once the operator is ready to receive the next item // and will invoke it again only when that item is delivered via emitter.onNext() (state, emitter) -> { // issue the async API call CompletableFuture<Void> f = state.nextValue( // handle the value received value -> { // we have the option to signal that item if (value % 2 == 0) { emitter.onNext(value); } else if (value == 101) { // or stop altogether, which will also trigger a cleanup emitter.onComplete(); } else { // or drop it and have the operator start a new call emitter.onNothing(); } } ); // This API call may not produce further items or fail f.whenComplete((done, error) -> { // As per the CompletableFuture API, error != null is the error outcome, // done is always null due to the Void type if (error != null) { emitter.onError(error); } else { emitter.onComplete(); } }); // In case the downstream cancels, the current API call // should be cancelled as well emitter.replaceCancellable(() -> f.cancel(true)); // some sources may want to create a fresh state object // after each invocation of this generator return state; }, // cleanup the state object state -> { state.close(); } )- Backpressure:
- The operator honors downstream backpressure.
- Scheduler:
generateAsyncdoes not operate by default on a particularScheduler, however, the signals emitted through theFlowableAsyncEmittermay happen on any thread, depending on the asynchronous API.
- Type Parameters:
T- the generated item typeS- the state associated with an individual subscription.- Parameters:
initialState- theSupplierthat returns a state object for each individualSubscriberto the returnedFlowable.asyncGenerator- theBiFunctioncalled with the current state value and theFlowableAsyncEmitterobject and should return a new state value as well as prepare and issue the async API call in a way that the call's outcome is (eventually) converted intoonNext,onErrororonCompletecalls. The operator ensures theBiFunctionis only invoked when the previous async call producedonNextitem and this item has been delivered to the downstream.stateCleanup- called at most once with the current state object to allow cleaning it up after the flow is cancelled or terminates viaEmitter.onError(Throwable)orEmitter.onComplete().- Returns:
- the new Flowable instance
- Since:
- 0.18.9
- See Also:
Flowable.generate(Supplier, BiFunction, Consumer),FlowableAsyncEmitter
-
-