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()) }
}
} catch (ex: BindCancellationException) {
receiver.internalError
receiver.result
}
}
@ -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)
}

View File

@ -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
}
}
@ -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
}
}

View File

@ -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
}
}