Package kotlinx.coroutines.rx2

Utilities for RxJava 2.x.

Types

Link copied to clipboard
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

Functions

Link copied to clipboard
fun Job.asCompletable(context: CoroutineContext): Completable

Converts this job to the hot reactive completable that signals with onCompleted when the corresponding job completes.

Link copied to clipboard
fun Scheduler.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Scheduler to an implementation of CoroutineDispatcher and provides native support of delay and withTimeout.

Link copied to clipboard
@JvmName(name = "asCoroutineDispatcher")
fun Scheduler.asCoroutineDispatcher0(): SchedulerCoroutineDispatcher
Link copied to clipboard
fun <T : Any> ObservableSource<T>.asFlow(): Flow<T>

Transforms given cold ObservableSource into cold Flow.

Link copied to clipboard
fun <T : Any> Flow<T>.asFlowable(context: CoroutineContext = EmptyCoroutineContext): Flowable<T>

Converts the given flow to a cold flowable. The original flow is cancelled when the flowable subscriber is disposed.

Link copied to clipboard
fun <T> Deferred<T?>.asMaybe(context: CoroutineContext): Maybe<T>

Converts this deferred value to the hot reactive maybe that signals onComplete, onSuccess or onError.

Link copied to clipboard
fun <T : Any> ReceiveChannel<T>.asObservable(context: CoroutineContext): Observable<T>

fun <T : Any> Flow<T>.asObservable(context: CoroutineContext = EmptyCoroutineContext): Observable<T>

Converts the given flow to a cold observable. The original flow is cancelled when the observable subscriber is disposed.

Link copied to clipboard
fun CoroutineDispatcher.asScheduler(): Scheduler

Converts an instance of CoroutineDispatcher to an implementation of Scheduler.

Link copied to clipboard
fun <T : Any> Deferred<T>.asSingle(context: CoroutineContext): Single<T>

Converts this deferred value to the hot reactive single that signals either onSuccess or onError.

Link copied to clipboard
suspend fun CompletableSource.await()

Awaits for completion of this completable without blocking the thread. Returns Unit, or throws the corresponding exception if this completable produces an error.

suspend fun <T> SingleSource<T>.await(): T

Awaits for completion of the single value response without blocking the thread. Returns the resulting value, or throws the corresponding exception if this response produces an error.

Link copied to clipboard
suspend fun <T> ObservableSource<T>.awaitFirst(): T

Awaits the first value from the given Observable without blocking the thread and returns the resulting value, or, if the observable has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> ObservableSource<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given Observable, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> ObservableSource<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given Observable, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> ObservableSource<T>.awaitFirstOrNull(): T?

Awaits the first value from the given Observable, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> ObservableSource<T>.awaitLast(): T

Awaits the last value from the given Observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> MaybeSource<T>.awaitSingle(): T

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or throws if either no value is produced or this MaybeSource produces an error.

suspend fun <T> ObservableSource<T>.awaitSingle(): T

Awaits the single value from the given observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

Link copied to clipboard
suspend fun <T> MaybeSource<T>.awaitSingleOrNull(): T?

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or null if no value is produced, or throws the corresponding exception if this MaybeSource produces an error.

Link copied to clipboard
inline suspend fun <T> MaybeSource<T>.collect(action: (T) -> Unit)

Subscribes to this MaybeSource and performs the specified action for each received element.

inline suspend fun <T> ObservableSource<T>.collect(action: (T) -> Unit)

Subscribes to this ObservableSource and performs the specified action for each received element.

Link copied to clipboard
fun rxCompletable(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit): Completable

Creates cold Completable that runs a given block in a coroutine and emits its result. Every time the returned completable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

Link copied to clipboard
fun <T : Any> rxFlowable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flowable<T>

Creates cold flowable that will run a given block in a coroutine. Every time the returned flowable is subscribed, it starts a new coroutine.

Link copied to clipboard
fun <T> rxMaybe(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Maybe<T>

Creates cold maybe that will run a given block in a coroutine and emits its result. If block result is null, onComplete is invoked without a value. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

Link copied to clipboard
fun <T : Any> rxObservable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Observable<T>

Creates cold observable that will run a given block in a coroutine. Every time the returned observable is subscribed, it starts a new coroutine.

Link copied to clipboard
fun <T : Any> rxSingle(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): Single<T>

Creates cold single that will run a given block in a coroutine and emits its result. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.