File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
common/kotlinx-coroutines-core-common Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ public interface CoroutineScope {
83
83
* This is a shorthand for `CoroutineScope(thisScope + context)`.
84
84
*/
85
85
public operator fun CoroutineScope.plus (context : CoroutineContext ): CoroutineScope =
86
- CoroutineScope (coroutineContext + context)
86
+ ContextScope (coroutineContext + context)
87
87
88
88
/* *
89
89
* Returns `true` when current [Job] is still active (has not completed and was not cancelled yet).
@@ -198,7 +198,12 @@ public suspend inline fun <R> currentScope(block: CoroutineScope.() -> R): R =
198
198
CoroutineScope (coroutineContext).block()
199
199
200
200
/* *
201
- * Creates [CoroutineScope] that wraps the given [coroutineContext].
201
+ * Creates [CoroutineScope] that wraps the given coroutine [context].
202
+ *
203
+ * If the given [context] does not contain a [Job] element, then a default `Job()` is created.
204
+ * This way, cancellation or failure or any child coroutine in this scope cancels all the other children,
205
+ * just like inside [coroutineScope] block.
202
206
*/
203
207
@Suppress(" FunctionName" )
204
- public fun CoroutineScope (context : CoroutineContext ): CoroutineScope = ContextScope (context)
208
+ public fun CoroutineScope (context : CoroutineContext ): CoroutineScope =
209
+ ContextScope (if (context[Job ] != null ) context else context + Job ())
Original file line number Diff line number Diff line change 4
4
5
5
package kotlinx.coroutines.experimental
6
6
7
+ import kotlinx.coroutines.experimental.internal.*
7
8
import kotlin.coroutines.experimental.*
8
9
import kotlin.test.*
9
10
@@ -205,5 +206,5 @@ class CoroutineScopeTest : TestBase() {
205
206
}
206
207
207
208
private fun scopePlusContext (c1 : CoroutineContext , c2 : CoroutineContext ) =
208
- (CoroutineScope (c1) + c2).coroutineContext
209
+ (ContextScope (c1) + c2).coroutineContext
209
210
}
You can’t perform that action at this time.
0 commit comments