public class ThreadController
public static ThreadController INSTANCE
@NotNull public kotlinx.coroutines.CoroutineDispatcher getIODispatcher()
public void init()
public void cancelAllNonUICoroutines()
This method cancels all coroutines that are children of this job. The call affects all coroutines that where started via ThreadController.ioScope.launch(). It is basically a kill switch for all non-UI scoped coroutines.
public void 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.
@NotNull public 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 class 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.
class JobControl@NotNull public JobControl getMainScopeAndRootJob()
Same as cancelAllNonUICoroutines, but using the MainThread dispatcher.
cancelAllNonUICoroutines