Sourabh Rawat
07/02/2021, 2:52 AMclass Executor {
// private val scope = CoroutineScope(Job() + Executors.newFixedThreadPool(10).asCoroutineDispatcher())
private val context = Executors.newFixedThreadPool(10).asCoroutineDispatcher()
suspend fun submit(value: Any) {
withContext(context) {
logger.debug { "Successfully received: $value" }
}
}
fun stop() {
// TODO
}
}
How can I cancel the submitted jobs? And fail submission of a new job if the context is "cancelled"Dominaezzz
07/02/2021, 5:22 AMSourabh Rawat
07/02/2021, 7:12 AMuli
07/02/2021, 9:00 AMclass Executor {
// private val scope = CoroutineScope(Job() + Executors.newFixedThreadPool(10).asCoroutineDispatcher())
private val dispatcher = Executors.newFixedThreadPool(10).asCoroutineDispatcher()
private val scope = CoroutineScope(Job() + dispatcher)
fun submit(value: Any) {
scope.launch {
logger.debug { "Successfully received: $value" }
}
}
fun stop() {
scope.cancel()
}
}