Skip to content

Commit

Permalink
Rename error to result in binding impls
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbull committed Mar 8, 2024
1 parent 8dc1cd0 commit 683b1b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public suspend inline fun <V, E> binding(crossinline block: suspend SuspendableR
with(receiver) { Ok(block()) }
}
} catch (ex: BindCancellationException) {
receiver.internalError
receiver.result
}
}

Expand All @@ -49,14 +49,14 @@ internal class SuspendableResultBindingImpl<E>(
) : SuspendableResultBinding<E> {

private val mutex = Mutex()
lateinit var internalError: Err<E>
lateinit var result: Err<E>

override suspend fun <V> Result<V, E>.bind(): V {
return when (this) {
is Ok -> value
is Err -> mutex.withLock {
if (::internalError.isInitialized.not()) {
internalError = this
if (::result.isInitialized.not()) {
result = this
this@SuspendableResultBindingImpl.cancel(BindCancellationException)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public inline fun <V, E> binding(crossinline block: ResultBinding<E>.() -> V): R
return try {
with(receiver) { Ok(block()) }
} catch (ex: BindException) {
receiver.error
receiver.result
}
}

Expand All @@ -45,13 +45,13 @@ public interface ResultBinding<E> {
@PublishedApi
internal class ResultBindingImpl<E> : ResultBinding<E> {

lateinit var error: Err<E>
lateinit var result: Err<E>

override fun <V> Result<V, E>.bind(): V {
return when (this) {
is Ok -> value
is Err -> {
this@ResultBindingImpl.error = this
this@ResultBindingImpl.result = this
throw BindException
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public suspend inline fun <V, E> binding(crossinline block: suspend ResultBindin
return try {
with(receiver) { Ok(block()) }
} catch (ex: BindException) {
receiver.error
receiver.result
}
}

0 comments on commit 683b1b7

Please sign in to comment.