Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created October 25, 2023 10:09
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 PatilShreyas/b7be1ab0ebb524980bde3f4c47012950 to your computer and use it in GitHub Desktop.
Save PatilShreyas/b7be1ab0ebb524980bde3f4c47012950 to your computer and use it in GitHub Desktop.
launch {
while (true) {
+ try {
delay(duration)
mutex.withLock {
// If the upstream flow has been completed and there are no values
// pending to emit in the collector, just break this loop.
if (isFlowCompleted && values.isEmpty()) {
return@launch
}
collector.emit(values.toList())
values.clear()
}
+ } catch (e: CancellationException) {
+ collector.emit(values.toList())
+ return@launch
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment