rxMaybe
fun <T> rxMaybe(
context: CoroutineContext = DefaultDispatcher,
parent: Job? = null,
block: suspend CoroutineScope.() -> T?
): Maybe<T>
Creates cold maybe that will run a given block in a coroutine. Every time the returned observable is subscribed, it starts a new coroutine. Coroutine returns a single, possibly null value. Unsubscribing cancels running coroutine.
Coroutine action | Signal to subscriber |
---|---|
Returns a non-null value | onSuccess |
Returns a null | onComplete |
Failure with exception or unsubscribe | onError |
The context for the new coroutine can be explicitly specified.
See CoroutineDispatcher for the standard context implementations that are provided by kotlinx.coroutines
.
The context of the parent coroutine from its scope may be used,
in which case the Job of the resulting coroutine is a child of the job of the parent coroutine.
The parent job may be also explicitly specified using parent parameter.
If the context does not have any dispatcher nor any other ContinuationInterceptor, then DefaultDispatcher is used.
Parameters
context
- context of the coroutine. The default value is DefaultDispatcher.
parent
- explicitly specifies the parent job, overrides job from the context (if any).
block
- the coroutine code.