-
-
Save PatilShreyas/b7be1ab0ebb524980bde3f4c47012950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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