Skip to content

Instantly share code, notes, and snippets.

Last active October 22, 2023 07:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
suspend fun collect(collector: FlowCollector<List<T>>) = coroutineScope<Unit> {
// For storing un-emitted values
val values = mutableListOf<T>()
// Continue looping after intervals `duration` and emit the items in the collector
// and clear the existing items from the `values`.
launch {
while (true) {
// Collect the upstream flow and add the items to the above `values` list
upstream.collect {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment