Skip to content

Commit

Permalink
Add autoCloseScope contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kyay10 committed Nov 15, 2024
1 parent 7b11fb7 commit f2c51bb
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@file:OptIn(ExperimentalContracts::class)

package arrow

import arrow.atomic.Atomic
import arrow.atomic.update
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.coroutines.cancellation.CancellationException

/**
Expand Down Expand Up @@ -62,6 +67,7 @@ import kotlin.coroutines.cancellation.CancellationException
* <!--- KNIT example-autocloseable-02.kt -->
*/
public inline fun <A> autoCloseScope(block: AutoCloseScope.() -> A): A {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
val scope = DefaultAutoCloseScope()
var throwable: Throwable? = null
return try {
Expand Down

0 comments on commit f2c51bb

Please sign in to comment.