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/d3c6646cf0042472c90b37f72524acbb to your computer and use it in GitHub Desktop.
Save pencelab/d3c6646cf0042472c90b37f72524acbb to your computer and use it in GitHub Desktop.
class MyComponent(private val myRepository: MyRepository): CoroutineScope by CoroutineScope(Dispatchers.IO) {
private val _mySharedFlow = MutableSharedFlow<Int>(2, 3, BufferOverflow.DROP_OLDEST)
val mySharedFlow: SharedFlow<Int>
get() = _mySharedFlow
fun fetchAndEmitList() = launch {
myRepository.getList().forEach {
log("Emitting => $it")
_mySharedFlow.emit(it)
delay(250)
}
}
fun release() {
this.coroutineContext[Job]?.cancelChildren()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment