execute

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.

Parameters

config

UseCaseConfig used to process results of internal Coroutine and to set configuration options.


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.

In case that an error is thrown during the execution of UseCase then UseCaseErrorHandler.globalOnErrorLogger is called with the error as an argument.

Parameters

args

Arguments used for initial use case initialization.

config

UseCaseConfig used to process results of internal Coroutine and to set configuration options.


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.

Return

Result that encapsulates either a successful result with Success or a failed result with Error


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.

UseCaseErrorHandler.globalOnErrorLogger is not used in this version of the execute method since it is recommended to call all execute methods with Result return type from launchWithHandler method where UseCaseErrorHandler.globalOnErrorLogger is used.

Return

Result that encapsulates either a successful result with Success or a failed result with Error

Parameters

args

Arguments used for initial use case initialization.


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


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.

In case that an error is thrown during the execution of FlowUseCase then UseCaseErrorHandler.globalOnErrorLogger is called with the error as an argument.

Parameters

args

Arguments used for initial use case initialization.

config

FlowUseCaseConfig used to process results of internal Flow and to set configuration options.