Skip to content

Commit

Permalink
Call finalizer in one place in finalizeCase
Browse files Browse the repository at this point in the history
  • Loading branch information
kyay10 committed Nov 1, 2024
1 parent 8e3eac6 commit 933607b
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,14 @@ internal suspend inline fun runReleaseAndRethrow(original: Throwable?, crossinli

@PublishedApi
internal inline fun <R> finalizeCase(block: () -> R, finalizer: (ExitCase) -> Unit): R {
var finished = false
var exitCase: ExitCase = ExitCase.Completed
return try {
block()
} catch (e: Throwable) {
finished = true
if (e !is CancellationException) e.nonFatalOrThrow()
finalizer(ExitCase.ExitCase(e))
exitCase = ExitCase.ExitCase(e)
throw e
} finally {
if (!finished) {
finalizer(ExitCase.Completed)
}
if (exitCase is ExitCase.Failure) exitCase.failure.nonFatalOrThrow()
finalizer(exitCase)
}
}

0 comments on commit 933607b

Please sign in to comment.