Package-level declarations

Types

Link copied to clipboard
class AccumulatorFlow<T>(sourceDataFlow: Flow<T>, scope: CoroutineScope) : AbstractFlow<T>

This Flow will have behaviour very similar to SharedFlow, but there are several differences:

Link copied to clipboard
interface ActorAction<T>
Link copied to clipboard

ExceptionHandler wrapper which was created to make possible to use handler across all coroutines calls

Link copied to clipboard
class DeferredAction<T, O>(val deferred: Deferred<T>, val callback: suspend (T) -> O)
Link copied to clipboard
class DoWithFirstBuilder<T>(scope: CoroutineScope)
Link copied to clipboard
typealias ExceptionHandler<T> = suspend (Throwable) -> T
Link copied to clipboard
class FlowOnHierarchyChangeListener(recursive: Boolean = false, _onChildViewAdded: MutableSharedFlow<Pair<View, View>> = MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE), _onChildViewRemoved: MutableSharedFlow<Pair<View, View>> = MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE)) : ViewGroup.OnHierarchyChangeListener

kotlinx.coroutines.flow.Flow-based android.view.ViewGroup.OnHierarchyChangeListener

Functions

Link copied to clipboard
fun <T> Channel<T>.accumulatorFlow(scope: CoroutineScope): Flow<T>

Creates AccumulatorFlow using this with receiveAsFlow to get

fun <T> Flow<T>.accumulatorFlow(scope: CoroutineScope): Flow<T>

Creates AccumulatorFlow using this as base Flow

Link copied to clipboard
fun <T> CoroutineScope.actor(channelCapacity: Int = Channel.UNLIMITED, block: suspend (T) -> Unit): Channel<T>
Link copied to clipboard
fun <T> CoroutineScope.actorAsync(channelCapacity: Int = Channel.UNLIMITED, markerFactory: suspend (T) -> Any? = { null }, block: suspend (T) -> Unit): Channel<T>
Link copied to clipboard
inline fun <T> CoroutineScope.asyncSafely(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, noinline onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, noinline block: suspend CoroutineScope.() -> T): Deferred<T>
Link copied to clipboard
inline fun <T> CoroutineScope.asyncSafelyWithoutExceptions(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend CoroutineScope.() -> T): Deferred<T?>
Link copied to clipboard
suspend fun <T> Iterable<Deferred<T>>.awaitFirst(cancelOthers: Boolean = true): T
suspend fun <T> Iterable<Deferred<T>>.awaitFirst(scope: CoroutineScope, cancelOnResult: Boolean = true): T
Link copied to clipboard
suspend fun <T> Iterable<Deferred<T>>.awaitFirstWithDeferred(scope: CoroutineScope, cancelOnResult: Boolean = true): Pair<Deferred<T>, T>
Link copied to clipboard
fun <T, O> Deferred<T>.buildAction(callback: suspend (T) -> O): DeferredAction<T, O>
Link copied to clipboard
inline fun CoroutineScope(context: CoroutineContext, noinline defaultExceptionsHandler: ExceptionHandler<Unit>): CoroutineScope
Link copied to clipboard
fun CoroutineScope.createActionsActor(): Channel<suspend () -> Unit>

Planned to use with doWithSuspending. Will execute incoming lambdas sequentially

Link copied to clipboard
inline fun CoroutineScope.createSafeActionsActor(noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler): Channel<suspend () -> Unit>

Planned to use with doWithSuspending. Will execute incoming lambdas sequentially

Link copied to clipboard
inline suspend fun <T> doIn(context: CoroutineContext, noinline block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
inline suspend fun <T> doInDefault(noinline block: suspend CoroutineScope.() -> T): T
doInIO
Link copied to clipboard
inline suspend fun <T> doInIO(noinline block: suspend CoroutineScope.() -> T): T
inline suspend fun <T> doInIO(noinline block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
inline suspend fun <T> doInUI(noinline block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
suspend fun <T> doOutsideOfCoroutine(block: () -> T): T

Call this method in case you need to do something in common thread (like reading of file in JVM)

doSynchronously
Link copied to clipboard
fun <T> doSynchronously(block: suspend CoroutineScope.() -> T): T
fun <T> CoroutineScope.doSynchronously(block: suspend CoroutineScope.() -> T): T
fun <T> doSynchronously(block: suspend CoroutineScope.() -> T): T
fun <T> CoroutineScope.doSynchronously(block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
suspend fun <T> Channel<suspend () -> Unit>.doWithSuspending(action: ActorAction<T>): T

Must be use with actor created by createActionsActor or createSafeActionsActor. Will send lambda which will execute action and return result.

Link copied to clipboard
fun <T> Flow<T>.filterNotNull(): Flow<T & Any>
Link copied to clipboard
suspend fun <T> List<Deferred<T>>.first(scope: CoroutineScope, cancelOnResult: Boolean = true): T
Link copied to clipboard
suspend fun <T> Flow<T?>.firstNotNull(): T
Link copied to clipboard
suspend fun <T> CoroutineScope.firstOf(vararg variants: Deferred<T>, cancelOnResult: Boolean = true): T
suspend fun <T> CoroutineScope.firstOf(cancelOnResult: Boolean = true, block: DoWithFirstBuilder<T>.() -> Unit): T
suspend fun <T> CoroutineScope.firstOf(variants: Iterable<Deferred<T>>, cancelOnResult: Boolean = true): T
Link copied to clipboard
@JvmName(name = "flatMapIterable")
inline fun <T, R> Flow<Iterable<T>>.flatMap(crossinline mapper: suspend (T) -> R): Flow<R>
inline fun <T, R> Flow<Flow<T>>.flatMap(crossinline mapper: suspend (T) -> R): Flow<R>
Link copied to clipboard
@JvmName(name = "flatMapNotNullIterable")
inline fun <T, R> Flow<Iterable<T>>.flatMapNotNull(crossinline mapper: suspend (T) -> R): Flow<R & Any>
inline fun <T, R> Flow<Flow<T>>.flatMapNotNull(crossinline mapper: suspend (T) -> R): Flow<R & Any>
Link copied to clipboard
@JvmName(name = "flattenIterable")
fun <T> Flow<Iterable<T>>.flatten(): Flow<T>
fun <T> Flow<Flow<T>>.flatten(): Flow<T>
Link copied to clipboard
inline suspend operator fun <T> FlowCollector<T>.invoke(value: T)
Link copied to clipboard
suspend fun <O> Iterable<DeferredAction<*, O>>.invokeFirstOf(scope: CoroutineScope, cancelOnResult: Boolean = true): O
suspend fun <O> invokeFirstOf(scope: CoroutineScope, vararg variants: DeferredAction<*, O>, cancelOnResult: Boolean = true): O
Link copied to clipboard
suspend fun <T, O> Iterable<Deferred<T>>.invokeOnFirst(scope: CoroutineScope, cancelOnResult: Boolean = true, callback: suspend (T) -> O): O
suspend fun <T, O> invokeOnFirst(scope: CoroutineScope, vararg variants: Deferred<T>, cancelOnResult: Boolean = true, callback: suspend (T) -> O): O
Link copied to clipboard
suspend fun <T, O> CoroutineScope.invokeOnFirstOf(cancelOnResult: Boolean = true, block: DoWithFirstBuilder<T>.() -> Unit, callback: suspend (T) -> O): O
Link copied to clipboard
inline fun CoroutineScope.launchSafely(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, noinline block: suspend CoroutineScope.() -> Unit): Job
Link copied to clipboard
inline fun CoroutineScope.launchSafelyWithoutExceptions(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, noinline onException: ExceptionHandler<Unit?> = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend CoroutineScope.() -> Unit): Job
launchSynchronously
Link copied to clipboard
fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T
fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T
fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T
fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
fun CoroutineContext.LinkedSupervisorJob(additionalContext: CoroutineContext? = null): Job
fun CoroutineScope.LinkedSupervisorJob(additionalContext: CoroutineContext? = null): Job
Link copied to clipboard
fun CoroutineScope.LinkedSupervisorScope(additionalContext: CoroutineContext? = null): CoroutineScope
Link copied to clipboard
inline operator fun <T> Flow<T>.plus(other: Flow<T>): Flow<T>
Link copied to clipboard
inline suspend fun <T> runCatchingSafely(noinline onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, noinline block: suspend CoroutineScope.() -> T): Result<T>
inline suspend fun <T, R> T.runCatchingSafely(noinline onException: ExceptionHandler<R> = defaultSafelyExceptionHandler, noinline block: suspend T.() -> R): Result<R>
Link copied to clipboard
inline suspend fun <T> runCatchingSafelyWithoutExceptions(noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend CoroutineScope.() -> T): Result<T?>
Link copied to clipboard
inline fun <T> CoroutineScope.safeActor(channelCapacity: Int = Channel.UNLIMITED, noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, crossinline block: suspend (T) -> Unit): Channel<T>
Link copied to clipboard
inline fun <T> CoroutineScope.safeActorAsync(channelCapacity: Int = Channel.UNLIMITED, noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, noinline markerFactory: suspend (T) -> Any? = { null }, crossinline block: suspend (T) -> Unit): Channel<T>
Link copied to clipboard
inline suspend fun <T> safely(noinline onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, noinline block: suspend CoroutineScope.() -> T): T

It will run block inside of supervisorScope to avoid problems with catching of exceptions

Link copied to clipboard
suspend fun <T> safelyWithContextExceptionHandler(contextExceptionHandler: ExceptionHandler<Unit>, safelyExceptionHandler: ExceptionHandler<T> = defaultSafelyExceptionHandler, block: suspend CoroutineScope.() -> T): T

This method will set new coroutineContext with ContextSafelyExceptionHandler. In case if coroutineContext already contains ContextSafelyExceptionHandler, ContextSafelyExceptionHandler.handler will be used BEFORE contextExceptionHandler in case of exception.

Link copied to clipboard
inline suspend fun <T> safelyWithoutExceptions(noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend CoroutineScope.() -> T): T?

Shortcut for safely with exception handler, that as expected must return null in case of impossible creating of result from exception (instead of throwing it, by default always returns null)

Link copied to clipboard
inline suspend fun <T> safelyWithResult(noinline block: suspend CoroutineScope.() -> T): Result<T>
inline suspend fun <T, R> T.safelyWithResult(noinline block: suspend T.() -> R): Result<R>
Link copied to clipboard

Use ViewGroup.setOnHierarchyChangeListener recursively for all available ViewGroups starting with this. This extension DO NOT guarantee that recursive subscription will happen after this method call

Link copied to clipboard
inline fun <T> Flow<T>.subscribe(scope: CoroutineScope, noinline block: suspend (T) -> Unit): Job

Shortcut for chain if Flow.onEach and Flow.launchIn

Link copied to clipboard
fun <T, M> Flow<T>.subscribeAsync(scope: CoroutineScope, markerFactory: suspend (T) -> M, block: suspend (T) -> Unit): Job
Link copied to clipboard
inline fun <T> Flow<T>.subscribeSafely(scope: CoroutineScope, noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, noinline block: suspend (T) -> Unit): Job

Use subscribe, but all blocks will be called inside of safely function. Use onException to set up your reaction for Throwables

Link copied to clipboard
inline fun <T, M> Flow<T>.subscribeSafelyAsync(scope: CoroutineScope, noinline markerFactory: suspend (T) -> M, noinline onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, noinline block: suspend (T) -> Unit): Job
Link copied to clipboard
inline fun <T> Flow<T>.subscribeSafelySkippingExceptions(scope: CoroutineScope, noinline block: suspend (T) -> Unit): Job

Use subscribeSafelyWithoutExceptions, but all exceptions inside of safely will be skipped

Link copied to clipboard
inline fun <T, M> Flow<T>.subscribeSafelySkippingExceptionsAsync(scope: CoroutineScope, noinline markerFactory: suspend (T) -> M, noinline block: suspend (T) -> Unit): Job
Link copied to clipboard
inline fun <T> Flow<T>.subscribeSafelyWithoutExceptions(scope: CoroutineScope, noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend (T) -> Unit): Job

Use subscribeSafelyWithoutExceptions, but all exceptions will be passed to defaultSafelyExceptionHandler

Link copied to clipboard
inline fun <T, M> Flow<T>.subscribeSafelyWithoutExceptionsAsync(scope: CoroutineScope, noinline markerFactory: suspend (T) -> M, noinline onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, noinline block: suspend (T) -> Unit): Job
Link copied to clipboard
fun <T> Flow<T>.takeNotNull(): Flow<T & Any>
Link copied to clipboard
fun <T> CoroutineScope.weakAsync(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): Deferred<T>
Link copied to clipboard
fun CoroutineScope.weakLaunch(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job

Properties

Link copied to clipboard
val <T> T.asDeferred: Deferred<T>
Link copied to clipboard
val Default: CoroutineDispatcher
Link copied to clipboard

This instance will be used in all calls of safely where exception handler has not been passed

Link copied to clipboard

This instance will be used in all calls of safelyWithoutExceptions as an exception handler for safely call

Use this handler in cases you wish to include handling of exceptions by defaultSafelyWithoutExceptionHandler and returning null at one time

Link copied to clipboard
val IO: CoroutineDispatcher
val IO: CoroutineDispatcher
Link copied to clipboard
val UI: MainCoroutineDispatcher