Mina Eweida
03/08/2020, 12:22 PMval singleScheduler = createSingleScheduler()
singleScheduler.newExecutor().submit {
// do something
}
Does everytime I do newExecutor().submit
here ensure it will run on the same thread like in java concurrent when we use Executors.newSingleThreadExecutor()
?Arkadii Ivanov
03/08/2020, 12:46 PMMina Eweida
03/08/2020, 1:06 PMval singleScheduler = createSingleScheduler()
val executor = singleScheduler.newExecutor()
singleScheduler.newExecutor().submit {
// do something
// At the end dispose
executor.dispose()
}
Arkadii Ivanov
03/08/2020, 1:20 PMsingleScheduler
top level property. This lives in process scope and does not require disposal. Also if you just need to execute a task in background you can use the following: completableFromFunction { ... }.subscribeOn(scheduler).subscribe()
. It will return Disposable for cancellation of needed.Mina Eweida
03/08/2020, 2:05 PM