I have this code ```class Executor { // pri...
# coroutines
s
I have this code
Copy code
class 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"
d
By cancelling that job object
s
I want to bulk cancel. Meaning I'll be calling submit multiple times.
u
Copy code
class 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()
    }
}