groostav
06/22/2017, 6:46 PMcontext
?
1 reply
I have no concrete problem, I'm just wondering how to write compossible code with access to that object. Given that I want to call a private suspend fun
from a suspend CoroutineScope.() -> Unit
block, what would be the most idiomatic way to pass that implicit CoroutineScope
object into my private function?
Maybe if, for example, my private suspend fun
had a hot-loop for use with a coroutine, and I wanted to structure that loop as while(isActive) { doHotThing() }
, whats the nicest way to do that.
My first thought would be to simply take a Job
CoroutineScope
as a parameter, but then the caller must pass this@lambda
as an argument to fill that parameter --or, of course, to structure the private fun
as an extension method itself.
My second thought was some kind of CoroutineLocal
that's updated by each coroutine initializer, but that's antithetical to the idea of "millions of fibres".
I cant help but feel like the concept of this pseudo-static baggage Job
and CoroutineScope
and etc doesn't have a particularly elegant solution yet.