stefano
03/08/2024, 10:11 AMsuspend fun
with something like GlobalContext.getContext().awaitSingle().informationINeed
. But I cannot write that code as-is in the method where it needs to run since the method is an override and doesn't have the suspend
modifier. I was considering wrapping the code with `runBlocking`; is this the way to go or am I missing something?renatomrcosta
03/08/2024, 10:25 AMsuspend fun myWrapper() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
blockingCodeHere()
}
Most literature tends to point to that being the solution: https://kt.academy/article/cc-dispatchers (last two paragraphs of the IO dispatcher tackle that).
If I understood you right, you have a blocker interface being implemented which you need to call from your suspending code. This way, the caller can wrap the overriden function.
If you have a override fun, and you need to call suspend functions from within, I suppose you could reach for the runBlocking, indeed.stefano
03/08/2024, 10:25 AMCLOVIS
03/08/2024, 4:32 PMCLOVIS
03/08/2024, 4:33 PMrunBlocking
, even transitively through a callchain that isn't suspendingstefano
03/08/2024, 4:36 PMCLOVIS
03/08/2024, 4:37 PMCoroutineScope
down as a regular argument, but you still wouldn't be able to suspend
, just launch
stuff in the parent's scope.CLOVIS
03/08/2024, 4:39 PMCoroutineScope
down to the function, and use runBlocking(parentScope)
, but honestly I'm not sure at all what it will do.stefano
03/08/2024, 4:41 PMCLOVIS
03/08/2024, 4:41 PMlaunch
'd?CLOVIS
03/08/2024, 4:43 PMstefano
03/08/2024, 4:57 PMstefano
03/08/2024, 4:59 PM