14
14
* limitations under the License.
15
15
*/
16
16
17
- // :todo: Remove after transition to Kotlin 1.2.30+
18
- @file:Suppress(" ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS" )
19
-
20
17
package kotlinx.coroutines.experimental
21
18
22
- import kotlinx.coroutines.experimental.internal.LockFreeLinkedListNode
23
- import kotlin.coroutines.experimental.Continuation
24
- import kotlin.coroutines.experimental.CoroutineContext
25
- import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
26
- import kotlin.coroutines.experimental.suspendCoroutine
19
+ import kotlinx.coroutines.experimental.internal.*
20
+ import kotlinx.coroutines.experimental.internalAnnotations.*
21
+ import kotlin.coroutines.experimental.*
22
+ import kotlin.coroutines.experimental.intrinsics.*
27
23
28
24
// --------------- cancellable continuations ---------------
29
25
@@ -61,24 +57,24 @@ import kotlin.coroutines.experimental.suspendCoroutine
61
57
*
62
58
* ```
63
59
*/
64
- public actual interface CancellableContinuation <in T > : Continuation <T >, Job {
60
+ public interface CancellableContinuation <in T > : Continuation <T >, Job {
65
61
/* *
66
62
* Returns `true` when this continuation is active -- it has not completed or cancelled yet.
67
63
*/
68
- public actual override val isActive: Boolean
64
+ public override val isActive: Boolean
69
65
70
66
/* *
71
67
* Returns `true` when this continuation has completed for any reason. A continuation
72
68
* that was cancelled is also considered complete.
73
69
*/
74
- public actual override val isCompleted: Boolean
70
+ public override val isCompleted: Boolean
75
71
76
72
/* *
77
73
* Returns `true` if this continuation was [cancelled][cancel].
78
74
*
79
75
* It implies that [isActive] is `false` and [isCompleted] is `true`.
80
76
*/
81
- public actual override val isCancelled: Boolean
77
+ public override val isCancelled: Boolean
82
78
83
79
/* *
84
80
* Tries to resume this continuation with a given value and returns non-null object token if it was successful,
@@ -90,7 +86,7 @@ public actual interface CancellableContinuation<in T> : Continuation<T>, Job {
90
86
*
91
87
* @suppress **This is unstable API and it is subject to change.**
92
88
*/
93
- public actual fun tryResume (value : T , idempotent : Any? = null): Any?
89
+ public fun tryResume (value : T , idempotent : Any? = null): Any?
94
90
95
91
/* *
96
92
* Tries to resume this continuation with a given exception and returns non-null object token if it was successful,
@@ -106,20 +102,20 @@ public actual interface CancellableContinuation<in T> : Continuation<T>, Job {
106
102
*
107
103
* @suppress **This is unstable API and it is subject to change.**
108
104
*/
109
- public actual fun completeResume (token : Any )
105
+ public fun completeResume (token : Any )
110
106
111
107
/* *
112
108
* Makes this continuation cancellable. Use it with `holdCancellability` optional parameter to
113
109
* [suspendCancellableCoroutine] function. It throws [IllegalStateException] if invoked more than once.
114
110
*/
115
- public actual fun initCancellability ()
111
+ public fun initCancellability ()
116
112
117
113
/* *
118
114
* Cancels this continuation with an optional cancellation [cause]. The result is `true` if this continuation was
119
115
* cancelled as a result of this invocation and `false` otherwise.
120
116
*/
121
117
@Suppress(" DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE" )
122
- public actual override fun cancel (cause : Throwable ? = null): Boolean
118
+ public override fun cancel (cause : Throwable ? = null): Boolean
123
119
124
120
/* *
125
121
* Registers handler that is **synchronously** invoked once on completion of this continuation.
@@ -135,23 +131,23 @@ public actual interface CancellableContinuation<in T> : Continuation<T>, Job {
135
131
* Installed [handler] should not throw any exceptions. If it does, they will get caught,
136
132
* wrapped into [CompletionHandlerException], and rethrown, potentially causing crash of unrelated code.
137
133
*/
138
- public actual override fun invokeOnCompletion (handler : CompletionHandler ): DisposableHandle
134
+ public override fun invokeOnCompletion (handler : CompletionHandler ): DisposableHandle
139
135
140
136
/* *
141
137
* Resumes this continuation with a given [value] in the invoker thread without going though
142
138
* [dispatch][CoroutineDispatcher.dispatch] function of the [CoroutineDispatcher] in the [context].
143
139
* This function is designed to be used only by the [CoroutineDispatcher] implementations themselves.
144
140
* **It should not be used in general code**.
145
141
*/
146
- public actual fun CoroutineDispatcher.resumeUndispatched (value : T )
142
+ public fun CoroutineDispatcher.resumeUndispatched (value : T )
147
143
148
144
/* *
149
145
* Resumes this continuation with a given [exception] in the invoker thread without going though
150
146
* [dispatch][CoroutineDispatcher.dispatch] function of the [CoroutineDispatcher] in the [context].
151
147
* This function is designed to be used only by the [CoroutineDispatcher] implementations themselves.
152
148
* **It should not be used in general code**.
153
149
*/
154
- public actual fun CoroutineDispatcher.resumeUndispatchedWithException (exception : Throwable )
150
+ public fun CoroutineDispatcher.resumeUndispatchedWithException (exception : Throwable )
155
151
}
156
152
157
153
/* *
@@ -163,7 +159,7 @@ public actual interface CancellableContinuation<in T> : Continuation<T>, Job {
163
159
*
164
160
* See [suspendAtomicCancellableCoroutine] for suspending functions that need *atomic cancellation*.
165
161
*/
166
- public actual inline suspend fun <T > suspendCancellableCoroutine (
162
+ public suspend inline fun <T > suspendCancellableCoroutine (
167
163
holdCancellability : Boolean = false,
168
164
crossinline block : (CancellableContinuation <T >) -> Unit
169
165
): T =
@@ -172,7 +168,7 @@ public actual inline suspend fun <T> suspendCancellableCoroutine(
172
168
if (! holdCancellability) cancellable.initCancellability()
173
169
block(cancellable)
174
170
cancellable.getResult()
175
- }
171
+ }
176
172
177
173
/* *
178
174
* Suspends coroutine similar to [suspendCancellableCoroutine], but with *atomic cancellation*.
@@ -182,7 +178,7 @@ public actual inline suspend fun <T> suspendCancellableCoroutine(
182
178
* continue to execute even after it was cancelled from the same thread in the case when the continuation
183
179
* was already resumed and was posted for execution to the thread's queue.
184
180
*/
185
- public actual inline suspend fun <T > suspendAtomicCancellableCoroutine (
181
+ public suspend inline fun <T > suspendAtomicCancellableCoroutine (
186
182
holdCancellability : Boolean = false,
187
183
crossinline block : (CancellableContinuation <T >) -> Unit
188
184
): T =
@@ -198,15 +194,15 @@ public actual inline suspend fun <T> suspendAtomicCancellableCoroutine(
198
194
* @suppress **This is unstable API and it is subject to change.**
199
195
*/
200
196
public fun CancellableContinuation <* >.removeOnCancel (node : LockFreeLinkedListNode ): DisposableHandle =
201
- invokeOnCompletion(handler = RemoveOnCancel (this , node))
197
+ invokeOnCompletion(handler = RemoveOnCancel (this , node).asHandler )
202
198
203
199
// --------------- implementation details ---------------
204
200
205
201
private class RemoveOnCancel (
206
202
cont : CancellableContinuation <* >,
207
- val node : LockFreeLinkedListNode
203
+ @JvmField val node : LockFreeLinkedListNode
208
204
) : JobNode<CancellableContinuation<*>>(cont) {
209
- override fun invoke (reason : Throwable ? ) {
205
+ override fun invoke (cause : Throwable ? ) {
210
206
if (job.isCancelled)
211
207
node.remove()
212
208
}
@@ -283,12 +279,16 @@ internal class CancellableContinuationImpl<in T>(
283
279
284
280
override fun nameString (): String =
285
281
" CancellableContinuation(${delegate.toDebugString()} )"
282
+
283
+ // todo: This workaround for KT-21968, should be removed in the future
284
+ public override fun cancel (cause : Throwable ? ): Boolean =
285
+ super .cancel(cause)
286
286
}
287
287
288
288
private class CompletedIdempotentResult (
289
289
@JvmField val idempotentResume : Any? ,
290
290
@JvmField val result : Any? ,
291
- @JvmField val token : JobSupport . Incomplete
291
+ @JvmField val token : Incomplete
292
292
) {
293
293
override fun toString (): String = " CompletedIdempotentResult[$result ]"
294
294
}
0 commit comments