Skip to content

Commit

Permalink
Merge pull request #240 from ephemient/kt/benchmark
Browse files Browse the repository at this point in the history
Ensure cleanup after runBlockingBenchmark
  • Loading branch information
ephemient authored Jan 10, 2025
2 parents 8890dac + bafeac4 commit 5e48f00
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import kotlinx.coroutines.completeWith
actual fun <T> runBlockingBenchmark(block: suspend CoroutineScope.() -> T): T {
val deferred = CompletableContinuation<T>(Dispatchers.Unconfined)
block.startCoroutine(CoroutineScope(deferred.context), deferred)
@OptIn(ExperimentalCoroutinesApi::class)
return deferred.getCompleted()
try {
@OptIn(ExperimentalCoroutinesApi::class)
return deferred.getCompleted()
} finally {
deferred.cancel()
}
}

@OptIn(InternalForInheritanceCoroutinesApi::class)
Expand Down

0 comments on commit 5e48f00

Please sign in to comment.