File tree 2 files changed +41
-7
lines changed
kotlinx-coroutines-core/common
2 files changed +41
-7
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
package kotlinx.coroutines
5
5
@@ -58,8 +58,8 @@ public enum class CoroutineStart {
58
58
ATOMIC ,
59
59
60
60
/* *
61
- * Immediately executes the coroutine until its first suspension point _in the current thread_ as if the
62
- * coroutine was started using [Dispatchers.Unconfined]. However, when the coroutine is resumed from suspension
61
+ * Immediately executes the coroutine until its first suspension point _in the current thread_ similarly to
62
+ * the coroutine being started using [Dispatchers.Unconfined]. However, when the coroutine is resumed from suspension
63
63
* it is dispatched according to the [CoroutineDispatcher] in its context.
64
64
*
65
65
* This is similar to [ATOMIC] in the sense that coroutine starts executing even if it was already cancelled,
@@ -68,9 +68,11 @@ public enum class CoroutineStart {
68
68
* Cancellability of coroutine at suspension points depends on the particular implementation details of
69
69
* suspending functions as in [DEFAULT].
70
70
*
71
- * **Note: This is an experimental api.** Execution semantics of coroutines may change in the future when this mode is used.
71
+ * ### Unconfined event loop
72
+ *
73
+ * Unlike [Dispatchers.Unconfined] and [MainCoroutineDispatcher.immediate], nested undispatched coroutines do not form
74
+ * an event loop that otherwise prevents potential stack overflow in case of unlimited nesting.
72
75
*/
73
- @ExperimentalCoroutinesApi // Since 1.0.0, no ETA on stability
74
76
UNDISPATCHED ;
75
77
76
78
/* *
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
5
package kotlinx.coroutines
@@ -31,6 +31,38 @@ class AtomicCancellationCommonTest : TestBase() {
31
31
expect(3 )
32
32
}
33
33
34
+ @Test
35
+ fun testUndispatchedLaunch () = runTest {
36
+ expect(1 )
37
+ assertFailsWith<CancellationException > {
38
+ withContext(Job ()) {
39
+ cancel()
40
+ launch(start = CoroutineStart .UNDISPATCHED ) {
41
+ expect(2 )
42
+ yield ()
43
+ expectUnreached()
44
+ }
45
+ }
46
+ }
47
+ finish(3 )
48
+ }
49
+
50
+ @Test
51
+ fun testUndispatchedLaunchWithUnconfinedContext () = runTest {
52
+ expect(1 )
53
+ assertFailsWith<CancellationException > {
54
+ withContext(Dispatchers .Unconfined + Job ()) {
55
+ cancel()
56
+ launch(start = CoroutineStart .UNDISPATCHED ) {
57
+ expect(2 )
58
+ yield ()
59
+ expectUnreached()
60
+ }
61
+ }
62
+ }
63
+ finish(3 )
64
+ }
65
+
34
66
@Test
35
67
fun testDeferredAwaitCancellable () = runTest {
36
68
expect(1 )
@@ -122,4 +154,4 @@ class AtomicCancellationCommonTest : TestBase() {
122
154
yield () // now yield
123
155
finish(4 )
124
156
}
125
- }
157
+ }
You can’t perform that action at this time.
0 commit comments