Skip to content

Commit

Permalink
Fix early return if CompletableDeferred is already completed
Browse files Browse the repository at this point in the history
  • Loading branch information
icepeppermint committed Jan 7, 2023
1 parent 2e094f4 commit a290434
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ class ComposedCoroutineCondition internal constructor(
private suspend fun completedAsync(ds: List<Deferred<Boolean>>) = coroutineScope {
val deferred = CompletableDeferred<Boolean>()
for (d in ds) {
if (d.isCompleted) {
break
}
if (deferred.isCompleted) break
d.invokeOnCompletion { e ->
if (e != null) {
completeExceptionally(deferred, e)
Expand All @@ -81,11 +79,9 @@ class ComposedCoroutineCondition internal constructor(
}
}
}
if (!deferred.isCompleted) {
launch {
ds.awaitAll()
complete(deferred, false)
}
if (!deferred.isCompleted) launch {
ds.awaitAll()
complete(deferred, false)
}
deferred
}
Expand Down

0 comments on commit a290434

Please sign in to comment.