Hi everyone, I wonder if someone could clarify something for me. When I first learned about coroutines, I remember being taught that one should prefer to use
launch
from your existing context and then move it elsewhere using
withContext
instead of calling
launch
and specifying dispatcher.
scope.launch { withContext(<http://Dispatchers.IO|Dispatchers.IO>) { work() } }
instead of
scope.launch(<http://Dispatchers.IO|Dispatchers.IO>) { work() }
. I remember this being described as preferential since there was some performance penalty when launching in a different context that did not occur when moving a running coroutine using
withContext
. I’m trying to find guidance on this again and I can’t find anything about it. Did I misunderstand something when I was first learning?