@@ -154,27 +154,25 @@ public interface Job : CoroutineContext.Element {
154
154
*/
155
155
public fun start (): Boolean
156
156
157
+
157
158
/* *
158
- * @suppress
159
+ * Cancels this job with an optional cancellation [cause].
160
+ * A cause can be used to specify an error message or to provide other details on
161
+ * a cancellation reason for debugging purposes.
162
+ * See [Job] documentation for full explanation of cancellation machinery.
159
163
*/
160
- @Suppress(" INAPPLICABLE_JVM_NAME" , " DEPRECATION" )
161
- @Deprecated(level = DeprecationLevel .HIDDEN , message = " Left here for binary compatibility" )
162
- @JvmName(" cancel" )
163
- public fun cancel0 (): Boolean = cancel(null )
164
+ public fun cancel (cause : CancellationException ? = null)
164
165
165
166
/* *
166
- * Cancels this job.
167
- * See [Job] documentation for full explanation of cancellation machinery.
167
+ * @suppress This method implements old version of JVM ABI. Use [cancel].
168
168
*/
169
- public fun cancel (): Unit
169
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility only" )
170
+ public fun cancel () = cancel(null )
170
171
171
172
/* *
172
- * @suppress
173
+ * @suppress This method has bad semantics when cause is not a [CancellationException]. Use [cancel].
173
174
*/
174
- @ObsoleteCoroutinesApi
175
- @Deprecated(level = DeprecationLevel .WARNING , message = " Use CompletableDeferred.completeExceptionally(cause) or Job.cancel() instead" ,
176
- replaceWith = ReplaceWith (" cancel()" )
177
- )
175
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility only" )
178
176
public fun cancel (cause : Throwable ? = null): Boolean
179
177
180
178
// ------------ parent-child ------------
@@ -479,21 +477,26 @@ public suspend fun Job.cancelAndJoin() {
479
477
}
480
478
481
479
/* *
482
- * @suppress
480
+ * Cancels all [children][Job.children] jobs of this coroutine using [Job.cancel] for all of them
481
+ * with an optional cancellation [cause].
482
+ * Unlike [Job.cancel] on this job as a whole, the state of this job itself is not affected.
483
483
*/
484
- @ObsoleteCoroutinesApi
485
- @Deprecated(level = DeprecationLevel .WARNING , message = " Use cancelChildren() without cause" , replaceWith = ReplaceWith (" cancelChildren()" ))
486
- public fun Job.cancelChildren (cause : Throwable ? = null) {
487
- @Suppress(" DEPRECATION" )
484
+ public fun Job.cancelChildren (cause : CancellationException ? = null) {
488
485
children.forEach { it.cancel(cause) }
489
486
}
490
487
491
488
/* *
492
- * Cancels all [children][Job.children] jobs of this coroutine using [Job.cancel] for all of them.
493
- * Unlike [Job.cancel] on this job as a whole, the state of this job itself is not affected.
489
+ * @suppress This method implements old version of JVM ABI. Use [cancel].
494
490
*/
495
- public fun Job.cancelChildren () {
496
- children.forEach { it.cancel() }
491
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility" )
492
+ public fun Job.cancelChildren () = cancelChildren(null )
493
+
494
+ /* *
495
+ * @suppress This method has bad semantics when cause is not a [CancellationException]. Use [Job.cancelChildren].
496
+ */
497
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility" )
498
+ public fun Job.cancelChildren (cause : Throwable ? = null) {
499
+ children.forEach { (it as ? JobSupport )?.cancelInternal(cause) }
497
500
}
498
501
499
502
// -------------------- CoroutineContext extensions --------------------
@@ -517,47 +520,49 @@ public fun Job.cancelChildren() {
517
520
public val CoroutineContext .isActive: Boolean
518
521
get() = this [Job ]?.isActive == true
519
522
520
-
521
523
/* *
522
- * @suppress
524
+ * Cancels [Job] of this context with an optional cancellation cause.
525
+ * See [Job.cancel] for details.
523
526
*/
524
- @Suppress(" unused" )
525
- @JvmName(" cancel" )
526
- @Deprecated(message = " Binary compatibility" , level = DeprecationLevel .HIDDEN )
527
- public fun CoroutineContext.cancel0 (): Boolean {
528
- this [Job ]?.cancel()
529
- return true
527
+ public fun CoroutineContext.cancel (cause : CancellationException ? = null) {
528
+ this [Job ]?.cancel(cause)
530
529
}
531
530
532
531
/* *
533
- * Cancels [Job] of this context. See [Job .cancel] for details .
532
+ * @suppress This method implements old version of JVM ABI. Use [CoroutineContext .cancel].
534
533
*/
535
- public fun CoroutineContext.cancel (): Unit {
536
- this [Job ]?.cancel()
537
- }
534
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility" )
535
+ public fun CoroutineContext.cancel () = cancel(null )
538
536
539
537
/* *
540
- * @suppress
538
+ * @suppress This method has bad semantics when cause is not a [CancellationException]. Use [CoroutineContext.cancel].
541
539
*/
542
- @ObsoleteCoroutinesApi
543
- @Deprecated(level = DeprecationLevel .WARNING , message = " Use cancel() without cause" , replaceWith = ReplaceWith (" cancel()" ))
540
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility" )
544
541
public fun CoroutineContext.cancel (cause : Throwable ? = null): Boolean =
545
542
@Suppress(" DEPRECATION" )
546
- this [Job ]?.cancel (cause) ? : false
543
+ ( this [Job ] as ? JobSupport )?.cancelInternal (cause) ? : false
547
544
548
545
/* *
549
- * Cancels all children of the [Job] in this context, without touching the the state of this job itself.
546
+ * Cancels all children of the [Job] in this context, without touching the the state of this job itself
547
+ * with an optional cancellation cause. See [Job.cancel].
550
548
* It does not do anything if there is no job in the context or it has no children.
551
549
*/
552
- public fun CoroutineContext.cancelChildren () {
553
- this [Job ]?.children?.forEach { it.cancel() }
550
+ public fun CoroutineContext.cancelChildren (cause : CancellationException ? = null ) {
551
+ this [Job ]?.children?.forEach { it.cancel(cause ) }
554
552
}
555
553
556
- @ObsoleteCoroutinesApi
557
- @Deprecated(level = DeprecationLevel .WARNING , message = " Use cancelChildren() without cause" , replaceWith = ReplaceWith (" cancelChildren()" ))
554
+ /* *
555
+ * @suppress This method implements old version of JVM ABI. Use [CoroutineContext.cancelChildren].
556
+ */
557
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility" )
558
+ public fun CoroutineContext.cancelChildren () = cancelChildren(null )
559
+
560
+ /* *
561
+ * @suppress This method has bad semantics when cause is not a [CancellationException]. Use [CoroutineContext.cancelChildren].
562
+ */
563
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " Binary compatibility" )
558
564
public fun CoroutineContext.cancelChildren (cause : Throwable ? = null) {
559
- @Suppress(" DEPRECATION" )
560
- this [Job ]?.children?.forEach { it.cancel(cause) }
565
+ this [Job ]?.children?.forEach { (it as ? JobSupport )?.cancelInternal(cause) }
561
566
}
562
567
563
568
/* *
0 commit comments