@@ -607,10 +607,10 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
607607 private inner class SelectOnJoinCompletionHandler (
608608 private val select : SelectInstance <* >
609609 ) : JobNode() {
610+ override val onCancelling: Boolean get() = false
610611 override fun invoke (cause : Throwable ? ) {
611612 select.trySelect(this @JobSupport, Unit )
612613 }
613- override val onCancelling: Boolean get() = false
614614 }
615615
616616 /* *
@@ -1263,10 +1263,10 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
12631263 private val child : ChildHandleNode ,
12641264 private val proposedUpdate : Any?
12651265 ) : JobNode() {
1266+ override val onCancelling get() = false
12661267 override fun invoke (cause : Throwable ? ) {
12671268 parent.continueCompleting(state, child, proposedUpdate)
12681269 }
1269- override val onCancelling: Boolean get() = false
12701270 }
12711271
12721272 private class AwaitContinuation <T >(
@@ -1378,12 +1378,12 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
13781378 private inner class SelectOnAwaitCompletionHandler (
13791379 private val select : SelectInstance <* >
13801380 ) : JobNode() {
1381+ override val onCancelling get() = false
13811382 override fun invoke (cause : Throwable ? ) {
13821383 val state = this @JobSupport.state
13831384 val result = if (state is CompletedExceptionally ) state else state.unboxState()
13841385 select.trySelect(this @JobSupport, result)
13851386 }
1386- override val onCancelling: Boolean get() = false
13871387 }
13881388}
13891389
@@ -1462,8 +1462,16 @@ internal abstract class JobNode : LockFreeLinkedListNode(), DisposableHandle, In
14621462 * Initialized by [JobSupport.invokeOnCompletionInternal].
14631463 */
14641464 lateinit var job: JobSupport
1465+
1466+ /* *
1467+ * If `false`, [invoke] will be called once the job is cancelled or is complete.
1468+ * If `true`, [invoke] is invoked as soon as the job becomes _cancelling_ instead, and if that doesn't happen,
1469+ * it will be called once the job is cancelled or is complete.
1470+ */
1471+ abstract val onCancelling: Boolean
14651472 override val isActive: Boolean get() = true
14661473 override val list: NodeList ? get() = null
1474+
14671475 override fun dispose () = job.removeNode(this )
14681476 override fun toString () = " $classSimpleName @$hexAddress [job@${job.hexAddress} ]"
14691477 /* *
@@ -1488,13 +1496,6 @@ internal abstract class JobNode : LockFreeLinkedListNode(), DisposableHandle, In
14881496 * (see [InvokeOnCompletion] and [InvokeOnCancelling]).
14891497 */
14901498 abstract fun invoke (cause : Throwable ? )
1491-
1492- /* *
1493- * If `false`, [invoke] will be called once the job is cancelled or is complete.
1494- * If `true`, [invoke] is invoked as soon as the job becomes _cancelling_ instead, and if that doesn't happen,
1495- * it will be called once the job is cancelled or is complete.
1496- */
1497- abstract val onCancelling: Boolean
14981499}
14991500
15001501internal class NodeList : LockFreeLinkedListHead (), Incomplete {
@@ -1529,20 +1530,21 @@ private class InactiveNodeList(
15291530private class InvokeOnCompletion (
15301531 private val handler : CompletionHandler
15311532) : JobNode() {
1532- override fun invoke (cause : Throwable ? ) = handler.invoke(cause)
15331533 override val onCancelling get() = false
1534+ override fun invoke (cause : Throwable ? ) = handler.invoke(cause)
15341535}
15351536
15361537private class ResumeOnCompletion (
15371538 private val continuation : Continuation <Unit >
15381539) : JobNode() {
1539- override fun invoke (cause : Throwable ? ) = continuation.resume(Unit )
15401540 override val onCancelling get() = false
1541+ override fun invoke (cause : Throwable ? ) = continuation.resume(Unit )
15411542}
15421543
15431544private class ResumeAwaitOnCompletion <T >(
15441545 private val continuation : CancellableContinuationImpl <T >
15451546) : JobNode() {
1547+ override val onCancelling get() = false
15461548 override fun invoke (cause : Throwable ? ) {
15471549 val state = job.state
15481550 assert { state !is Incomplete }
@@ -1555,7 +1557,6 @@ private class ResumeAwaitOnCompletion<T>(
15551557 continuation.resume(state.unboxState() as T )
15561558 }
15571559 }
1558- override val onCancelling get() = false
15591560}
15601561
15611562// -------- invokeOnCancellation nodes
@@ -1565,17 +1566,17 @@ private class InvokeOnCancelling(
15651566) : JobNode() {
15661567 // delegate handler shall be invoked at most once, so here is an additional flag
15671568 private val _invoked = atomic(false )
1569+ override val onCancelling get() = true
15681570 override fun invoke (cause : Throwable ? ) {
15691571 if (_invoked .compareAndSet(expect = false , update = true )) handler.invoke(cause)
15701572 }
1571- override val onCancelling get() = true
15721573}
15731574
15741575private class ChildHandleNode (
15751576 @JvmField val childJob : ChildJob
15761577) : JobNode(), ChildHandle {
15771578 override val parent: Job get() = job
1579+ override val onCancelling: Boolean get() = true
15781580 override fun invoke (cause : Throwable ? ) = childJob.parentCancelled(job)
15791581 override fun childCancelled (cause : Throwable ): Boolean = job.childCancelled(cause)
1580- override val onCancelling: Boolean get() = true
15811582}
0 commit comments