-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Description
sample code
val scope = CoroutineScope(Dispatchers.Default)
val sharedFlow = flow {
while (true) {
emit(Unit)
delay(1.seconds)
}
}.onEach {
println("Emitted")
}.shareIn(
scope,
started = SharingStarted.WhileSubscribed(),
)
val job = Job()
runBlocking {
//5 listeners
repeat(5) { listenerId ->
launch(job) {
sharedFlow.collect {
println("Collected by $listenerId")
}
}
}
delay(10.seconds)
job.complete()
println("Done")
}
Output last part:
Collected by 0
Collected by 1
Collected by 2
Collected by 3
Collected by 4
Emitted
Emitted
Collected by kotlin.Unit
Collected by kotlin.Unit
Collected by kotlin.Unit
Collected by kotlin.Unit
Collected by kotlin.Unit
Collected by 0
Collected by 1
Collected by 2
Collected by 3
Collected by 4
Emitted
Collected by 0
Collected by 1
Collected by 2
Collected by 3
Collected by 4
see Collected by kotlin.Unit
This is problematic, you won't see this happen while running as regular jvm project.
Metadata
Metadata
Assignees
Labels
No labels