julioromano
05/03/2021, 1:36 PMCoroutineScope?
As if the CoroutineScope were a message queue and Jobs were messages in it: Would there be a way to track if the CoroutineScope is currently handling Jobs or is sitting idle?
What I’m trying to accomplish: I’d like to build an idle/busy signal (possibly as a Flow<Boolean>) that will tell me whether a CoroutineScope is currently running any coroutines or not.Erik
05/03/2021, 1:57 PMJob. Job has `children: Sequence<Job>`: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/children.html
Maybe you can transform that sequence to a Flow<Boolean>? I haven't use that sequence ever, though, so I'm not sure how it behaves over time as children appear, start, complete, fail, cancel, etc.julioromano
05/03/2021, 1:59 PMErik
05/03/2021, 2:05 PMjobs.any { it.isActive } or isCancelled or isCompleted, and emit that into a Flow<Boolean>.julioromano
05/03/2021, 2:15 PMlaunch() was part of the CoroutineScope interface. But it’s an extension function 😞louiscad
05/03/2021, 2:17 PMJob interface, though there might be other ways to satisfy that with a dedicated API or changes.Erik
05/03/2021, 2:29 PMJob.children property were a Flow<Sequence<Job>> (or a flow of some other iterable type, not sure why it must be a sequence).louiscad
05/03/2021, 2:30 PMFlow with some compatibility for old code relying on the Sequence.Erik
05/03/2021, 2:36 PMErik
05/03/2021, 2:39 PMMutableSharedFlow.subscriptionCount: StateFlow<Int>.elizarov
05/03/2021, 3:34 PMjulioromano
05/03/2021, 4:06 PMBut why do you need this idle/busy signal? What are you ultimately trying to do?Would love to show a loading indicator in a UI that turns on whenever there are background jobs running. All background jobs are launched as children of a well known
CoroutineScope .Erik
05/03/2021, 4:11 PMviewModelScope 😉julioromano
05/03/2021, 4:13 PMI’m heavily suspectingNope, this is happening in a pure Kotlin KMM module (no Android, no JDK…)😉viewModelScope
julioromano
05/07/2021, 12:57 PMelizarov
05/09/2021, 12:50 PMkotlinx.coroutines. The Job APi that tracks new children (attachChild) is internal and is in state of flux. We can try designing some public API that would expose the information you need (essentially, it could be a StateFlow with a number of children), but that’s non-trivial either. Job is highly performance sensitive, so it’ll likely mean that we’ll have to design some separate “watchable job” subclass…. seems too much of an API surface.elizarov
05/09/2021, 12:51 PMStateFlow, which you can then observe for your “busy indicator”.