Object RxUtils
-
- All Implemented Interfaces:
public class RxUtils
-
-
Method Summary
Modifier and Type Method Description final static <T extends Any> Observable<T>
onBackpressureBuffer(Observable<T> $self)
Instructs an Observable that is emitting items faster than its observer can consume them to buffer these items indefinitely until they can be emitted. final static <T extends Any> Subscription
subscribe(Observable<T> $self, Subscriber<in T> subscriber)
Subscribe to the Observable final static <T extends Any> Subscription
subscribe(Observable<T> $self, Function1<T, Unit> onNext)
Subscribe to the Observable. final static <T extends Any> Pair<T, Throwable>
await(Observable<T> $self)
Blocks the current thread and waits for the Observable to complete, then returns a Pair containing the result, and the error (if any) This must not be called from the Main thread (and will throw an IllegalStateException if done so) as that would freeze the UI final static <T extends Any> Subscriber<T>
createActionSubscriber(Action1<in T> onNext, Action1<Throwable> onError, Action0 onCompleted)
Creates a subscriber that forwards the onXXX method calls to callbacks. final static <T extends Any> Subscriber<T>
createActionSubscriber(Action1<in T> onNext, Action1<Throwable> onError)
Creates a subscriber that forwards the onXXX method calls to callbacks. final static <T extends Any> Subscriber<T>
createActionSubscriber(Action1<in T> onNext)
Creates a subscriber that forwards the onXXX method calls to callbacks. final static Observable<Long>
timer(Long delay, TimeUnit unit)
Returns an Observable that emits 0L
after a specified delay, and then completes.final static Subscription
schedule(Long delay, TimeUnit unit, Function1<Long, Unit> callback)
Runs the callback after the specified delay final static <T extends Any, R extends Any> Observable<R>
combineLatest(List<Observable<T>> sources, FuncN<R> combineFunction)
Combines a list of source Observables by emitting an item that aggregates the latest values of each of the source Observables each time an item is received from any of the source Observables, where this aggregation is defined by a specified function. final static <T extends Any, R extends Any> Observable<R>
map(Observable<T> $self, Function1<T, R> func)
Returns an Observable that applies a specified function to each item emitted by the source Observable and emits the results of these function applications. final static <T extends Any, R extends Any> Observable<R>
switchMap(Observable<T> $self, Function1<T, Observable<R>> func)
Returns a new Observable by applying a function that you supply to each item emitted by the source Observable that returns an Observable, and then emitting the items emitted by the most recently emitted of these Observables. final static Observable<Object>
getEmpty()
-
-
Method Detail
-
onBackpressureBuffer
final static <T extends Any> Observable<T> onBackpressureBuffer(Observable<T> $self)
Instructs an Observable that is emitting items faster than its observer can consume them to buffer these items indefinitely until they can be emitted.
Backpressure
:The operator honors backpressure from downstream and consumes the source Observable in an unbounded manner (i.e., not applying backpressure to it).
Scheduler
:onBackpressureBuffer does not operate by default on a particular Scheduler.
-
subscribe
final static <T extends Any> Subscription subscribe(Observable<T> $self, Subscriber<in T> subscriber)
Subscribe to the Observable
- Parameters:
subscriber
- the Subscriber that will handle emissions and notifications from the Observable
-
subscribe
final static <T extends Any> Subscription subscribe(Observable<T> $self, Function1<T, Unit> onNext)
Subscribe to the Observable. This is equivalent to subscribe(createActionSubscriber(onNext))
- Parameters:
onNext
- the callback that will be fired once the Observable emits onNext
-
await
final static <T extends Any> Pair<T, Throwable> await(Observable<T> $self)
Blocks the current thread and waits for the Observable to complete, then returns a Pair containing the result, and the error (if any) This must not be called from the Main thread (and will throw an IllegalStateException if done so) as that would freeze the UI
-
createActionSubscriber
@JvmOverloads() final static <T extends Any> Subscriber<T> createActionSubscriber(Action1<in T> onNext, Action1<Throwable> onError, Action0 onCompleted)
Creates a subscriber that forwards the onXXX method calls to callbacks.
- Parameters:
onNext
- An Observable calls this method whenever the Observable emits an item.onError
- An Observable calls this method to indicate that it has failed to generate the expected data or has encountered some other error.onCompleted
- An Observable calls this method after it has called onNext for the final time, if it has not encountered any errors.
-
createActionSubscriber
@JvmOverloads() final static <T extends Any> Subscriber<T> createActionSubscriber(Action1<in T> onNext, Action1<Throwable> onError)
Creates a subscriber that forwards the onXXX method calls to callbacks.
- Parameters:
onNext
- An Observable calls this method whenever the Observable emits an item.onError
- An Observable calls this method to indicate that it has failed to generate the expected data or has encountered some other error.
-
createActionSubscriber
@JvmOverloads() final static <T extends Any> Subscriber<T> createActionSubscriber(Action1<in T> onNext)
Creates a subscriber that forwards the onXXX method calls to callbacks.
- Parameters:
onNext
- An Observable calls this method whenever the Observable emits an item.
-
timer
final static Observable<Long> timer(Long delay, TimeUnit unit)
Returns an Observable that emits
0L
after a specified delay, and then completes.- Parameters:
delay
- the initial delay before emitting a single0L
unit
- time units to use for delay
-
schedule
final static Subscription schedule(Long delay, TimeUnit unit, Function1<Long, Unit> callback)
Runs the callback after the specified delay
- Parameters:
delay
- the delay before running the callbackunit
- time unit to use for the delaycallback
- the callback to run after the delay
-
combineLatest
final static <T extends Any, R extends Any> Observable<R> combineLatest(List<Observable<T>> sources, FuncN<R> combineFunction)
Combines a list of source Observables by emitting an item that aggregates the latest values of each of the source Observables each time an item is received from any of the source Observables, where this aggregation is defined by a specified function.
- Parameters:
sources
- the list of source ObservablescombineFunction
- the aggregation function used to combine the items emitted by the source Observables
-
map
final static <T extends Any, R extends Any> Observable<R> map(Observable<T> $self, Function1<T, R> func)
Returns an Observable that applies a specified function to each item emitted by the source Observable and emits the results of these function applications.
- Parameters:
func
- a function to apply to each item emitted by the Observable
-
switchMap
final static <T extends Any, R extends Any> Observable<R> switchMap(Observable<T> $self, Function1<T, Observable<R>> func)
Returns a new Observable by applying a function that you supply to each item emitted by the source Observable that returns an Observable, and then emitting the items emitted by the most recently emitted of these Observables.
The resulting Observable completes if both the upstream Observable and the last inner Observable, if any, complete. If the upstream Observable signals an onError, the inner Observable is unsubscribed and the error delivered in-sequence.
- Parameters:
func
- a function that, when applied to an item emitted by the source Observable, returns an Observable
-
-
-
-