[jOOQ/jOOQ#14997] Use awaitSingle instead of awaitFirstOrNull in transactionCoroutine to correctly sequence transaction script
This commit is contained in:
parent
cbad6561b8
commit
1b1808558e
@ -1,7 +1,8 @@
|
||||
package org.jooq.kotlin.coroutines
|
||||
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.reactive.awaitFirstOrNull
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlinx.coroutines.reactive.awaitSingle
|
||||
import kotlinx.coroutines.reactor.mono
|
||||
import org.jooq.Configuration
|
||||
import org.jooq.DSLContext
|
||||
@ -10,20 +11,18 @@ import org.jooq.DSLContext
|
||||
// Extensions to bridge between the reactive-streams and the coroutine world
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
suspend fun <T> DSLContext.transactionCoroutine(transactional: suspend (Configuration) -> T): T {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return transactionPublisher { c ->
|
||||
mono {
|
||||
transactional.invoke(c)
|
||||
}
|
||||
}.awaitFirstOrNull() as T
|
||||
}
|
||||
suspend fun <T> DSLContext.transactionCoroutine(transactional: suspend (Configuration) -> T): T =
|
||||
transactionCoroutine(EmptyCoroutineContext, transactional)
|
||||
|
||||
|
||||
suspend fun <T> DSLContext.transactionCoroutine(context: CoroutineContext, transactional: suspend (Configuration) -> T): T {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
// [#14997] Wrap values in an auxiliary class in order to allow nulls, which awaitSingle()
|
||||
// doesn't allow, otherwise
|
||||
data class Wrap<T>(val t: T)
|
||||
|
||||
return transactionPublisher { c ->
|
||||
mono(context) {
|
||||
transactional.invoke(c)
|
||||
Wrap(transactional.invoke(c))
|
||||
}
|
||||
}.awaitFirstOrNull() as T
|
||||
}.awaitSingle().t
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user