Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pencelab/058c57a75862e893f8c76fc85b249950 to your computer and use it in GitHub Desktop.
Save pencelab/058c57a75862e893f8c76fc85b249950 to your computer and use it in GitHub Desktop.
val myFlow = MutableSharedFlow<String>(replay = 10)
...
val job = launch(Dispatchers.Default) {
delay(750)
myFlow
.onStart {
log("Collector started collecting...")
}
.collect {
log("Collected => $it")
}
}
...
launch {
listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).forEach {
log("Emitting => $it")
myFlow.emit("$it")
delay(100)
}
job.cancel()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment