Make runBlockingTest match signature of kotlinx-coroutines-test

This commit is contained in:
Michael Bull 2020-08-26 19:26:02 +01:00
parent a76768fa42
commit b123921ba5
3 changed files with 13 additions and 3 deletions

View File

@ -43,7 +43,7 @@ internal class SuspendableResultBindingImpl<E> : SuspendableResultBinding<E> {
is Ok -> value
is Err -> {
mutex.withLock {
if (::internalError.isInitialized.not()){
if (::internalError.isInitialized.not()) {
internalError = this
}
}

View File

@ -1,9 +1,14 @@
package com.github.michaelbull.result.coroutines
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
/**
* Workaround to use suspending functions in unit tests for multiplatform/native projects.
* Solution was found here: https://github.com/Kotlin/kotlinx.coroutines/issues/885#issuecomment-446586161
*/
expect fun runBlockingTest(block: suspend (scope : CoroutineScope) -> Unit)
expect fun runBlockingTest(
context: CoroutineContext = EmptyCoroutineContext,
testBody: suspend CoroutineScope.() -> Unit
)

View File

@ -2,5 +2,10 @@ package com.github.michaelbull.result.coroutines
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlin.coroutines.CoroutineContext
actual fun runBlockingTest(block: suspend (scope : CoroutineScope) -> Unit) = runBlocking { block(this) }
actual fun runBlockingTest(context: CoroutineContext, testBody: suspend CoroutineScope.() -> Unit) {
runBlocking {
testBody(this)
}
}