diff --git a/kt/aoc2024-exe/src/nonblockingBench/kotlin/com/github/ephemient/aoc2024/exe/RunBlockingBenchmark.kt b/kt/aoc2024-exe/src/nonblockingBench/kotlin/com/github/ephemient/aoc2024/exe/RunBlockingBenchmark.kt index 818913ac..bdb71baa 100644 --- a/kt/aoc2024-exe/src/nonblockingBench/kotlin/com/github/ephemient/aoc2024/exe/RunBlockingBenchmark.kt +++ b/kt/aoc2024-exe/src/nonblockingBench/kotlin/com/github/ephemient/aoc2024/exe/RunBlockingBenchmark.kt @@ -16,8 +16,12 @@ import kotlinx.coroutines.completeWith actual fun runBlockingBenchmark(block: suspend CoroutineScope.() -> T): T { val deferred = CompletableContinuation(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)