Rename error to result in binding impls

This commit is contained in:
Michael Bull 2024-03-08 14:12:27 +00:00
parent 5c4635b655
commit 01c8c00f98
3 changed files with 8 additions and 8 deletions

View File

@ -33,7 +33,7 @@ public suspend inline fun <V, E> binding(crossinline block: suspend SuspendableR
with(receiver) { Ok(block()) } with(receiver) { Ok(block()) }
} }
} catch (ex: BindCancellationException) { } catch (ex: BindCancellationException) {
receiver.internalError receiver.result
} }
} }
@ -49,14 +49,14 @@ internal class SuspendableResultBindingImpl<E>(
) : SuspendableResultBinding<E> { ) : SuspendableResultBinding<E> {
private val mutex = Mutex() private val mutex = Mutex()
lateinit var internalError: Err<E> lateinit var result: Err<E>
override suspend fun <V> Result<V, E>.bind(): V { override suspend fun <V> Result<V, E>.bind(): V {
return when (this) { return when (this) {
is Ok -> value is Ok -> value
is Err -> mutex.withLock { is Err -> mutex.withLock {
if (::internalError.isInitialized.not()) { if (::result.isInitialized.not()) {
internalError = this result = this
this@SuspendableResultBindingImpl.cancel(BindCancellationException) this@SuspendableResultBindingImpl.cancel(BindCancellationException)
} }

View File

@ -32,7 +32,7 @@ public inline fun <V, E> binding(crossinline block: ResultBinding<E>.() -> V): R
return try { return try {
with(receiver) { Ok(block()) } with(receiver) { Ok(block()) }
} catch (ex: BindException) { } catch (ex: BindException) {
receiver.error receiver.result
} }
} }
@ -45,13 +45,13 @@ public interface ResultBinding<E> {
@PublishedApi @PublishedApi
internal class ResultBindingImpl<E> : ResultBinding<E> { internal class ResultBindingImpl<E> : ResultBinding<E> {
lateinit var error: Err<E> lateinit var result: Err<E>
override fun <V> Result<V, E>.bind(): V { override fun <V> Result<V, E>.bind(): V {
return when (this) { return when (this) {
is Ok -> value is Ok -> value
is Err -> { is Err -> {
this@ResultBindingImpl.error = this this@ResultBindingImpl.result = this
throw BindException throw BindException
} }
} }

View File

@ -27,6 +27,6 @@ public suspend inline fun <V, E> binding(crossinline block: suspend ResultBindin
return try { return try {
with(receiver) { Ok(block()) } with(receiver) { Ok(block()) }
} catch (ex: BindException) { } catch (ex: BindException) {
receiver.error receiver.result
} }
} }