Skip to content

Commit

Permalink
Add to test function two params, start and context
Browse files Browse the repository at this point in the history
- `start: CoroutineStart` uses `UNDISPATCHED` as default param
- `context: CoroutineContext` uses `Unconfined` as default param
  • Loading branch information
JavierSegoviaCordoba committed Jan 27, 2021
1 parent a71a167 commit 0fc6cba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/commonMain/kotlin/app/cash/turbine/FlowTurbine.kt
Expand Up @@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.seconds
Expand All @@ -52,12 +53,13 @@ private const val debug = false
@ExperimentalCoroutinesApi // For start=UNDISPATCHED
suspend fun <T> Flow<T>.test(
timeout: Duration = 1.seconds,
context: CoroutineContext = Unconfined,
validate: suspend FlowTurbine<T>.() -> Unit
) {
coroutineScope {
val events = Channel<Event<T>>(UNLIMITED)

val collectJob = launch(start = UNDISPATCHED, context = Unconfined) {
val collectJob = launch(start = UNDISPATCHED, context = context) {
val terminalEvent = try {
if (debug) println("Collect starting!")
collect { item ->
Expand Down Expand Up @@ -186,9 +188,11 @@ sealed class Event<out T> {
object Complete : Event<Nothing>() {
override fun toString() = "Complete"
}

data class Error(val throwable: Throwable) : Event<Nothing>() {
override fun toString() = "Error(${throwable::class.simpleName})"
}

data class Item<T>(val value: T) : Event<T>() {
override fun toString() = "Item($value)"
}
Expand Down

0 comments on commit 0fc6cba

Please sign in to comment.