Skip to content

Commit 3de2be4

Browse files
r4zzz4kqwwdfsad
authored andcommitted
Fixed CoroutineScope.plus operator
Fixes #559
1 parent 44d28cd commit 3de2be4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

common/kotlinx-coroutines-core-common/src/CoroutineScope.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public interface CoroutineScope {
8383
* This is a shorthand for `CoroutineScope(thisScope + context)`.
8484
*/
8585
public operator fun CoroutineScope.plus(context: CoroutineContext): CoroutineScope =
86-
CoroutineScope(context + context)
86+
CoroutineScope(coroutineContext + context)
8787

8888
/**
8989
* Returns `true` when current [Job] is still active (has not completed and was not cancelled yet).

common/kotlinx-coroutines-core-common/test/CoroutineScopeTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package kotlinx.coroutines.experimental
66

7+
import kotlin.coroutines.experimental.*
78
import kotlin.test.*
89

910
class CoroutineScopeTest : TestBase() {
@@ -191,4 +192,18 @@ class CoroutineScopeTest : TestBase() {
191192
finish(4)
192193
}
193194
}
195+
196+
@Test
197+
fun testScopePlusContext() {
198+
assertSame(EmptyCoroutineContext, scopePlusContext(EmptyCoroutineContext, EmptyCoroutineContext))
199+
assertSame(Dispatchers.Default, scopePlusContext(EmptyCoroutineContext, Dispatchers.Default))
200+
assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Default, EmptyCoroutineContext))
201+
assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Default, Dispatchers.Default))
202+
assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Unconfined, Dispatchers.Default))
203+
assertSame(Dispatchers.Unconfined, scopePlusContext(Dispatchers.Default, Dispatchers.Unconfined))
204+
assertSame(Dispatchers.Unconfined, scopePlusContext(Dispatchers.Unconfined, Dispatchers.Unconfined))
205+
}
206+
207+
private fun scopePlusContext(c1: CoroutineContext, c2: CoroutineContext) =
208+
(CoroutineScope(c1) + c2).coroutineContext
194209
}

0 commit comments

Comments
 (0)