Skip to content

Commit

Permalink
Rollback changes in Bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Nov 8, 2023
1 parent cf4ea7a commit dd4960d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ import kotlin.jvm.JvmName
* -->
* ```kotlin
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
*
* ```
*
Expand Down Expand Up @@ -374,7 +374,7 @@ import kotlin.jvm.JvmName
* import kotlinx.coroutines.awaitCancellation
*
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
*
* suspend fun <A> CompletableDeferred<A>.getOrNull(): A? =
* if (isCompleted) await() else null
Expand Down Expand Up @@ -413,7 +413,7 @@ import kotlin.jvm.JvmName
* import kotlinx.coroutines.awaitCancellation
*
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
*
* suspend fun <A> CompletableDeferred<A>.getOrNull(): A? =
* if (isCompleted) await() else null
Expand Down Expand Up @@ -552,7 +552,7 @@ import kotlin.jvm.JvmName
* }
*
* suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
* guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
* guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }
* -->
* ```kotlin
* suspend fun main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.awaitCancellation

suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }

suspend fun main() {
val error = "Error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.awaitCancellation

suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }

suspend fun <A> CompletableDeferred<A>.getOrNull(): A? =
if (isCompleted) await() else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.awaitCancellation

suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }

suspend fun <A> CompletableDeferred<A>.getOrNull(): A? =
if (isCompleted) await() else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun readFile(path: String?): Effect<FileError, Content> = effect {
}

suspend fun <A> awaitExitCase(exit: CompletableDeferred<ExitCase>): A =
guaranteeCase({ awaitCancellation() }) { exitCase -> exit.complete(exitCase) }
guaranteeCase(::awaitCancellation) { exitCase -> exit.complete(exitCase) }

suspend fun main() {
val exit = CompletableDeferred<ExitCase>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public sealed class ExitCase {
* @see guarantee for registering a handler that is guaranteed to always run.
* @see guaranteeCase for registering a handler that executes for any [ExitCase].
*/
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
public suspend inline fun <A> onCancel(
fa: () -> A,
fa: suspend () -> A,
crossinline onCancel: suspend () -> Unit
): A = guaranteeCase(fa) { case ->
when (case) {
Expand All @@ -54,8 +55,9 @@ public suspend inline fun <A> onCancel(
* @param finalizer handler to run after [fa].
* @see guaranteeCase for registering a handler that tracks the [ExitCase] of [fa].
*/
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
public suspend inline fun <A> guarantee(
fa: () -> A,
fa: suspend () -> A,
crossinline finalizer: suspend () -> Unit
): A {
val res = try {
Expand Down Expand Up @@ -83,8 +85,9 @@ public suspend inline fun <A> guarantee(
* @param finalizer handler to run after [fa].
* @see guarantee for registering a handler that ignores the [ExitCase] of [fa].
*/
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
public suspend inline fun <A> guaranteeCase(
fa: () -> A,
fa: suspend () -> A,
crossinline finalizer: suspend (ExitCase) -> Unit
): A {
val res = try {
Expand Down Expand Up @@ -138,9 +141,10 @@ public suspend inline fun <A> guaranteeCase(
* ```
* <!--- KNIT example-bracket-01.kt -->
*/
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
public suspend inline fun <A, B> bracket(
crossinline acquire: suspend () -> A,
use: (A) -> B,
use: suspend (A) -> B,
crossinline release: suspend (A) -> Unit
): B {
val acquired = withContext(NonCancellable) {
Expand Down Expand Up @@ -221,9 +225,10 @@ public suspend inline fun <A, B> bracket(
* ```
* <!--- KNIT example-bracket-02.kt -->
*/
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
public suspend inline fun <A, B> bracketCase(
crossinline acquire: suspend () -> A,
use: (A) -> B,
use: suspend (A) -> B,
crossinline release: suspend (A, ExitCase) -> Unit
): B {
val acquired = withContext(NonCancellable) {
Expand Down

0 comments on commit dd4960d

Please sign in to comment.