Object ThreadController
-
- All Implemented Interfaces:
public class ThreadController
-
-
Field Summary
Fields Modifier and Type Field Description private final CoroutineDispatcherIODispatcherpublic final static ThreadControllerINSTANCE
-
Method Summary
Modifier and Type Method Description final Unitinit()final UnitcancelAllNonUICoroutines()This method cancels all coroutines that are children of io and navigator jobs. final UnitcancelAllUICoroutines()This method cancels all coroutines that are children of this job. final JobControlgetIOScopeAndRootJob()This method creates a Job object that is a child of the ioRootJob. final JobControlgetMainScopeAndRootJob()Same as getIOScopeAndRootJob, but using the MainThread dispatcher. final CoroutineDispatchergetIODispatcher()
-
-
-
Method Detail
-
cancelAllNonUICoroutines
final Unit cancelAllNonUICoroutines()
This method cancels all coroutines that are children of io and navigator jobs. The call affects all coroutines that where started via ThreadController.ioScope.launch() and ThreadController.navigatorScope.launch(). It is basically a kill switch for all non-UI scoped coroutines.
-
cancelAllUICoroutines
final Unit cancelAllUICoroutines()
This method cancels all coroutines that are children of this job. The call affects all coroutines that where started via ThreadController.mainScope.launch(). It is basically a kill switch for all UI scoped coroutines.
-
getIOScopeAndRootJob
final JobControl getIOScopeAndRootJob()
This method creates a Job object that is a child of the ioRootJob. Using this job a CoroutineScope is created. The return object is the JobControl data class. This data class contains both the new Job object and the CoroutineScope that uses the Job object. This construct allows the caller to cancel all coroutines created from the returned CoroutineScope. Example: val jobController:JobController = ThreadController.getIOScopeAndRootJob() val job_1 = jobController.ioScope.launch{ doSomethingUsefull_1()} val job_2 = jobController.ioScope.launch{ doSomethingUsefull_2()} val job_3 = jobController.ioScope.launch{ doSomethingUsefull_3()} val job_4 = jobController.ioScope.launch{ doSomethingUsefull_4()}
The code launches four coroutines. Each one becomes a parent of ThreadController.job To cancel all coroutines: jobController.job.cancel() To cancel a specific coroutine: job_1.cancel(), etc.
-
getMainScopeAndRootJob
final JobControl getMainScopeAndRootJob()
Same as getIOScopeAndRootJob, but using the MainThread dispatcher.
-
getIODispatcher
final CoroutineDispatcher getIODispatcher()
-
-