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

Link copied to clipboard
sealed interface SmartMutex

It is interface which will work like classic Mutex, but in difference have lockStateFlow for listening of the SmartMutex state.

Link copied to clipboard
class SmartRWLocker(readPermits: Int = Int.MAX_VALUE, writeIsLocked: Boolean = false)

Composite mutex which works with next rules:

Link copied to clipboard
sealed interface SmartSemaphore

It is interface which will work like classic Semaphore, but in difference have permitsStateFlow for listening of the SmartSemaphore state.

Link copied to clipboard
open class SpecialMutableStateFlow<T>(initialValue: T) : MutableStateFlow<T> , FlowCollector<T> , MutableSharedFlow<T>

Works like StateFlow, but guarantee that latest value update will always be delivered to each active subscriber

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
Link copied to clipboard
val UI: MainCoroutineDispatcher

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
fun <T> CoroutineScope.asyncSafely(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, block: suspend CoroutineScope.() -> T): Deferred<T>
Link copied to clipboard
fun <T> CoroutineScope.asyncSafelyWithoutExceptions(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, 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
fun CoroutineScope(context: CoroutineContext, 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
Link copied to clipboard
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)

Link copied to clipboard
fun <T> doSynchronously(block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
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> invokeFirstOf(scope: CoroutineScope, vararg variants: DeferredAction<*, O>, cancelOnResult: Boolean = true): O
Link copied to clipboard
suspend fun <O> Iterable<DeferredAction<*, O>>.invokeFirstOf(scope: CoroutineScope, cancelOnResult: Boolean = true): O
Link copied to clipboard
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> Iterable<Deferred<T>>.invokeOnFirst(scope: CoroutineScope, 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
fun <T> launchInCurrentThread(block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
fun CoroutineScope.launchSafely(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, block: suspend CoroutineScope.() -> Unit): Job
Link copied to clipboard
fun CoroutineScope.launchSafelyWithoutExceptions(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, onException: ExceptionHandler<Unit?> = defaultSafelyWithoutExceptionHandlerWithNull, block: suspend CoroutineScope.() -> Unit): Job
Link copied to clipboard
fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T
Link copied to clipboard
fun CoroutineScope.LinkedSupervisorJob(additionalContext: CoroutineContext? = null): CoroutineContext
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
suspend fun preloadImage(src: String): Image
Link copied to clipboard
suspend fun <T> runCatchingSafely(onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, block: suspend CoroutineScope.() -> T): Result<T>
Link copied to clipboard
suspend fun <T, R> T.runCatchingSafely(onException: ExceptionHandler<R> = defaultSafelyExceptionHandler, block: suspend T.() -> R): Result<R>
Link copied to clipboard
suspend fun <T> runCatchingSafelyWithoutExceptions(onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, 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
suspend fun <T> safely(onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, 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
suspend fun <T> safelyWithoutExceptions(onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, 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
suspend fun <T> safelyWithResult(block: suspend CoroutineScope.() -> T): Result<T>
Link copied to clipboard
suspend fun <T, R> T.safelyWithResult(block: suspend T.() -> R): Result<R>
Link copied to clipboard
suspend fun selectFileOrNull(inputSetup: (HTMLInputElement) -> Unit = {}, onFailure: (Throwable) -> Unit = {}): MPPFile?
Link copied to clipboard
suspend fun selectFileOrThrow(inputSetup: (HTMLInputElement) -> Unit = {}): MPPFile
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
fun <T, M> Flow<T>.subscribeSafelyAsync(scope: CoroutineScope, markerFactory: suspend (T) -> M, onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, 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
fun <T, M> Flow<T>.subscribeSafelySkippingExceptionsAsync(scope: CoroutineScope, markerFactory: suspend (T) -> M, 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
fun <T, M> Flow<T>.subscribeSafelyWithoutExceptionsAsync(scope: CoroutineScope, markerFactory: suspend (T) -> M, onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, block: suspend (T) -> Unit): Job
Link copied to clipboard
fun <T> Flow<T>.takeNotNull(): Flow<T & Any>
Link copied to clipboard
suspend fun Blob.toByteArray(): ByteArray
Link copied to clipboard
Link copied to clipboard
suspend fun SmartRWLocker.waitReadRelease(permits: Int = 1): Int

Will wait until the SmartSemaphore.permitsStateFlow of this instance will have permits count free permits.

Link copied to clipboard
suspend fun SmartSemaphore.waitRelease(permits: Int = 1): Int

Will wait until the SmartSemaphore.permitsStateFlow of this instance will have permits count free permits.

Link copied to clipboard

Will wait until the SmartMutex.lockStateFlow of this instance will be false.

Link copied to clipboard

Will wait until the SmartMutex.lockStateFlow of this instance will be false.

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
Link copied to clipboard
inline suspend fun <T> SmartSemaphore.Mutable.withAcquire(permits: Int = 1, action: () -> T): T

Will call SmartSemaphore.Mutable.lock, then execute action and return the result after SmartSemaphore.Mutable.unlock

Link copied to clipboard
inline suspend fun <T> SmartMutex.Mutable.withLock(action: () -> T): T

Will call SmartMutex.Mutable.lock, then execute action and return the result after SmartMutex.Mutable.unlock

Link copied to clipboard
inline suspend fun <T> SmartRWLocker.withReadAcquire(action: () -> T): T

Will call SmartSemaphore.Mutable.lock, then execute action and return the result after SmartSemaphore.Mutable.unlock

Link copied to clipboard
inline suspend fun <T> SmartRWLocker.withWriteLock(action: () -> T): T

Will call SmartMutex.Mutable.lock, then execute action and return the result after SmartMutex.Mutable.unlock