@@ -320,7 +320,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
320
320
private fun notifyCancelling (list : NodeList , cause : Throwable ) {
321
321
// first cancel our own children
322
322
onCancelling(cause)
323
- list.closeForSome( )
323
+ list.close( LIST_CANCELLATION_PERMISSION )
324
324
notifyHandlers<JobCancellingNode >(list, cause)
325
325
// then cancel parent
326
326
cancelParent(cause) // tentative cancellation -- does not matter if there is no parent
@@ -353,7 +353,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
353
353
}
354
354
355
355
private fun NodeList.notifyCompletion (cause : Throwable ? ) {
356
- close()
356
+ close(LIST_MAX_PERMISSION )
357
357
notifyHandlers<JobNode >(this , cause)
358
358
}
359
359
@@ -466,13 +466,13 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
466
466
if (onCancelling) {
467
467
val rootCause = (state as ? Finishing )?.let { synchronized(it) { it.rootCause } }
468
468
if (rootCause == null ) {
469
- list.addLast(node, allowedAfterPartialClosing = false )
469
+ list.addLast(node, LIST_CANCELLATION_PERMISSION )
470
470
} else {
471
471
if (invokeImmediately) handler.invoke(rootCause)
472
472
return NonDisposableHandle
473
473
}
474
474
} else {
475
- list.addLast(node, allowedAfterPartialClosing = true )
475
+ list.addLast(node, LIST_MAX_PERMISSION )
476
476
}
477
477
}
478
478
when {
@@ -987,7 +987,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
987
987
// or we are adding a child to a coroutine that is not completing yet
988
988
if (maybeRootCause == null || ! state.isCompleting) {
989
989
// Note: add node the list while holding lock on state (make sure it cannot change)
990
- if (! list.addLast(node, allowedAfterPartialClosing = true ))
990
+ if (! list.addLast(node, LIST_MAX_PERMISSION ))
991
991
return @tryPutNodeIntoList false // retry
992
992
// just return the node if we don't have to invoke the handler (not cancelling yet)
993
993
rootCause = maybeRootCause ? : return @tryPutNodeIntoList true
@@ -1000,7 +1000,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1000
1000
}
1001
1001
node.invoke(rootCause)
1002
1002
return handle
1003
- } else list.addLast(node, allowedAfterPartialClosing = true ).also { success ->
1003
+ } else list.addLast(node, LIST_MAX_PERMISSION ).also { success ->
1004
1004
if (success) {
1005
1005
/* * Handling the following case:
1006
1006
* - A child requested to be added to the list;
@@ -1347,6 +1347,9 @@ private val SEALED = Symbol("SEALED")
1347
1347
private val EMPTY_NEW = Empty (false )
1348
1348
private val EMPTY_ACTIVE = Empty (true )
1349
1349
1350
+ private const val LIST_MAX_PERMISSION = Int .MAX_VALUE
1351
+ private const val LIST_CANCELLATION_PERMISSION = 0
1352
+
1350
1353
private class Empty (override val isActive : Boolean ) : Incomplete {
1351
1354
override val list: NodeList ? get() = null
1352
1355
override fun toString (): String = " Empty{${if (isActive) " Active" else " New" } }"
0 commit comments