-
public interface CoroutineScopeOwnerThis 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classCoroutineScopeOwner.UseCaseConfigHolds references to lambdas and some basic configuration used to process results of Coroutine use case. Use UseCaseConfig.Builder to construct this object.
public final classCoroutineScopeOwner.FlowUseCaseConfigHolds references to lambdas and some basic configuration used to process results of Flow use case. Use FlowUseCaseConfig.Builder to construct this object.
-
Method Summary
Modifier and Type Method Description CoroutineDispatchergetWorkerDispatcher()Provides Dispatcher for background tasks. <T extends Any> Unitexecute(UseCase<Unit, T> $self, Function1<CoroutineScopeOwner.UseCaseConfig.Builder<T>, Unit> config)Asynchronously executes use case and saves it's Deferred. <ARGS extends Any, T extends Any> Unitexecute(UseCase<ARGS, T> $self, ARGS args, Function1<CoroutineScopeOwner.UseCaseConfig.Builder<T>, Unit> config)Asynchronously executes use case and saves it's Deferred. <T extends Any> Result<T>execute(UseCase<Unit, T> $self, Boolean cancelPrevious)Synchronously executes use case and saves it's Deferred. <ARGS extends Any, T extends Any> Result<T>execute(UseCase<ARGS, T> $self, ARGS args, Boolean cancelPrevious)Synchronously executes use case and saves it's Deferred. <T extends Any> Unitexecute(FlowUseCase<Unit, T> $self, Function1<CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>, Unit> config)<ARGS extends Any, T extends Any> Unitexecute(FlowUseCase<ARGS, T> $self, ARGS args, Function1<CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>, Unit> config)Asynchronously executes use case and consumes data from flow on UI thread. UnitlaunchWithHandler(SuspendFunction1<CoroutineScope, Unit> block)Launch suspend block in coroutineScope. UnitdefaultErrorHandler(Throwable exception)This method is called when coroutine launched with launchWithHandler throws an exception and this exception isn't CancellationException. abstract CoroutineScopegetCoroutineScope()CoroutineScope scope used to execute coroutine based use cases. -
-
Method Detail
-
getWorkerDispatcher
CoroutineDispatcher getWorkerDispatcher()
Provides Dispatcher for background tasks. This may be overridden for testing purposes
-
execute
<T extends Any> Unit execute(UseCase<Unit, T> $self, Function1<CoroutineScopeOwner.UseCaseConfig.Builder<T>, Unit> config)
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.
-
execute
<ARGS extends Any, T extends Any> Unit execute(UseCase<ARGS, T> $self, ARGS args, Function1<CoroutineScopeOwner.UseCaseConfig.Builder<T>, Unit> config)
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.
-
execute
<T extends Any> Result<T> execute(UseCase<Unit, T> $self, Boolean cancelPrevious)
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.
-
execute
<ARGS extends Any, T extends Any> Result<T> execute(UseCase<ARGS, T> $self, ARGS args, Boolean cancelPrevious)
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.
- Parameters:
args- Arguments used for initial use case initialization.
-
execute
<T extends Any> Unit execute(FlowUseCase<Unit, T> $self, Function1<CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>, Unit> config)
-
execute
<ARGS extends Any, T extends Any> Unit execute(FlowUseCase<ARGS, T> $self, ARGS args, Function1<CoroutineScopeOwner.FlowUseCaseConfig.Builder<T>, Unit> config)
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.
-
launchWithHandler
Unit launchWithHandler(SuspendFunction1<CoroutineScope, Unit> block)
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.
If exception is CancellationException then defaultErrorHandler is not called and UseCaseErrorHandler.globalOnErrorLogger is called only if the root cause of this exception is not CancellationException (e.g. when Result.getOrCancel is used).
-
defaultErrorHandler
Unit defaultErrorHandler(Throwable exception)
This method is called when coroutine launched with launchWithHandler throws an exception and this exception isn't CancellationException. By default, it rethrows this exception.
-
getCoroutineScope
abstract CoroutineScope getCoroutineScope()
CoroutineScope scope used to execute coroutine based use cases. It is your responsibility to cancel it when all running tasks should be stopped
-
-
-
-