Does CoroutineScope coroutineContext carry to default context for any of that class's "launch"?

I’ve got what I believe is latest best-practice:

class BasicBot : CoroutineScope, AutoCloseable, Runnable {
    private val job = Job()

    override val coroutineContext: CoroutineContext
        get() = job + Dispatchers.Default

    override fun run() {
        launch(Dispatchers.Default) {

Is that launch(Dispatchers.Default) redundant with the previously declared coroutineContext that uses Default? Hard to tell from the docs what influences nested defaults where. Thank you!

My overall goal is to “Launch stuff on the Default dispatcher so it uses reasonable parallelism, and don’t leave any running when the AutoClosable closes.”

Yes, it is redundant. launch() is an extension function, so it is equivalent to this.launch(), so it uses this.coroutineContext's dispatcher, which in this case is Dispatchers.Default.

1 Like

Even more: Dispatchers.Default in coroutineContext redudant too, coroutine builders will provide default dispatcher if it missing for some reason. But it’s okay to explicitly provide a dispatcher.