CoroutineScopeOwner

interface CoroutineScopeOwner

This interface gives your class ability to execute UseCase and FlowUseCase Coroutine use cases. You may find handy to implement this interface in custom Presenters, ViewHolders etc. It is your responsibility to cancel coroutineScope when when all running tasks should be stopped.

Types

Link copied to clipboard
class FlowUseCaseConfig<T>

Holds references to lambdas and some basic configuration used to process results of Flow use case. Use FlowUseCaseConfig.Builder to construct this object.

Link copied to clipboard
class UseCaseConfig<T>

Holds references to lambdas and some basic configuration used to process results of Coroutine use case. Use UseCaseConfig.Builder to construct this object.

Functions

Link copied to clipboard
open fun defaultErrorHandler(exception: Throwable)

This method is called when coroutine launched with launchWithHandler throws an exception and this exception isn't CancellationException. By default, it rethrows this exception.

Link copied to clipboard
open fun <T> FlowUseCase<Unit, T>.execute(config: CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>.() -> Unit)

open suspend fun <T> UseCase<Unit, T>.execute(cancelPrevious: Boolean = true): Result<T>

Synchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the cancelPrevious. This version is used for use cases without initial arguments.

open fun <T> UseCase<Unit, T>.execute(config: CoroutineScopeOwner.UseCaseConfig.Builder<T>.() -> Unit)

Asynchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the config. This version is used for use cases without initial arguments.

open fun <ARGS, T> FlowUseCase<ARGS, T>.execute(args: ARGS, config: CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>.() -> Unit)

Asynchronously executes use case and consumes data from flow on UI thread. By default all previous pending executions are canceled, this can be changed by config. When suspend function in use case finishes, onComplete is called on UI thread. This version is gets initial arguments by args.

open suspend fun <ARGS, T> UseCase<ARGS, T>.execute(args: ARGS, cancelPrevious: Boolean = true): Result<T>

Synchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the cancelPrevious. This version gets initial arguments by args.

open fun <ARGS, T> UseCase<ARGS, T>.execute(args: ARGS, config: CoroutineScopeOwner.UseCaseConfig.Builder<T>.() -> Unit)

Asynchronously executes use case and saves it's Deferred. By default all previous pending executions are canceled, this can be changed by the config. This version gets initial arguments by args.

Link copied to clipboard
open fun getWorkerDispatcher(): CoroutineDispatcher

Provides Dispatcher for background tasks. This may be overridden for testing purposes

Link copied to clipboard
open fun launchWithHandler(block: suspend CoroutineScope.() -> Unit)

Launch suspend block in coroutineScope. Encapsulates this call with try catch block and when an exception is thrown then it is logged in UseCaseErrorHandler.globalOnErrorLogger and handled by defaultErrorHandler.

Properties

Link copied to clipboard
abstract val coroutineScope: CoroutineScope

CoroutineScope scope used to execute coroutine based use cases. It is your responsibility to cancel it when all running tasks should be stopped

Inheritors

Link copied to clipboard