Skip to content

Instantly share code, notes, and snippets.

@digitalbuddha
Created September 2, 2019 14:02
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 digitalbuddha/ac741321738a8f3000935580fbbd6265 to your computer and use it in GitHub Desktop.
Save digitalbuddha/ac741321738a8f3000935580fbbd6265 to your computer and use it in GitHub Desktop.
val networkTrigger = Channel<Unit>(capacity = Channel.RENDEZVOUS)
val diskCommands = Channel<DiskCommand>(capacity = Channel.RENDEZVOUS)
launch {
// trigger first load
diskCommands.send(DiskCommand.ReadFirst)
}
val networkFlow = networkTrigger
.consumeAsFlow()
.filter { it }
.flatMapLatest { fetcher.stream(request) }
.doOnEach { diskCommands.send(DiskCommand.Stop(stopAck)); write(it) }
.map{ diskCommands.send(DiskCommand.Read(it))}
val diskFlow = flattenMerge(diskCommands.consumeAsFlow(), networkFlow)
.flatmapLatest{ when (command) {....} //something from here can call networkTrigger(Unit) to kick off network request
return diskFlow //not sure what combine is needed for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment