Fix tests
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
b201b40639
commit
5c6fee08fd
@@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.job
|
||||
import kotlinx.coroutines.plus
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
|
||||
/**
|
||||
* Create a child scope of the current scope.
|
||||
@@ -28,6 +29,11 @@ fun CoroutineScope.childScope(
|
||||
dispatcher: CoroutineDispatcher,
|
||||
name: String,
|
||||
): CoroutineScope = run {
|
||||
val supervisorJob = SupervisorJob(parent = coroutineContext.job)
|
||||
this + dispatcher + supervisorJob + CoroutineName(name)
|
||||
if (this is TestScope) {
|
||||
// Special case for tests: we can't start a coroutine with a different SupervisorJob
|
||||
this
|
||||
} else {
|
||||
val supervisorJob = SupervisorJob(parent = coroutineContext.job)
|
||||
this + dispatcher + supervisorJob + CoroutineName(name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user