@@ -136,10 +136,9 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
136
136
/* *
137
137
* Initializes parent job.
138
138
* It shall be invoked at most once after construction after all other initialization.
139
- * @suppress **This is unstable API and it is subject to change.**
140
139
*/
141
140
internal fun initParentJobInternal (parent : Job ? ) {
142
- check( parentHandle == null )
141
+ assert { parentHandle == null }
143
142
if (parent == null ) {
144
143
parentHandle = NonDisposableHandle
145
144
return
@@ -269,8 +268,8 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
269
268
270
269
// fast-path method to finalize normally completed coroutines without children
271
270
private fun tryFinalizeSimpleState (state : Incomplete , update : Any? , mode : Int ): Boolean {
272
- check( state is Empty || state is JobNode <* >) // only simple state without lists where children can concurrently add
273
- check( update !is CompletedExceptionally ) // only for normal completion
271
+ assert { state is Empty || state is JobNode <* > } // only simple state without lists where children can concurrently add
272
+ assert { update !is CompletedExceptionally } // only for normal completion
274
273
if (! _state .compareAndSet(state, update.boxIncomplete())) return false
275
274
onCancelling(null ) // simple state is not a failure
276
275
onCompletionInternal(update)
@@ -397,16 +396,14 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
397
396
*/
398
397
internal open fun onStartInternal () {}
399
398
400
- public final override fun getCancellationException (): CancellationException {
401
- val state = this .state
402
- return when (state) {
399
+ public final override fun getCancellationException (): CancellationException =
400
+ when (val state = this .state) {
403
401
is Finishing -> state.rootCause?.toCancellationException(" $classSimpleName is cancelling" )
404
402
? : error(" Job is still new or active: $this " )
405
403
is Incomplete -> error(" Job is still new or active: $this " )
406
404
is CompletedExceptionally -> state.cause.toCancellationException()
407
405
else -> JobCancellationException (" $classSimpleName has completed normally" , null , this )
408
406
}
409
- }
410
407
411
408
protected fun Throwable.toCancellationException (message : String? = null): CancellationException =
412
409
this as ? CancellationException ? :
@@ -747,8 +744,8 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
747
744
748
745
// try make new Cancelling state on the condition that we're still in the expected state
749
746
private fun tryMakeCancelling (state : Incomplete , rootCause : Throwable ): Boolean {
750
- check( state !is Finishing ) // only for non-finishing states
751
- check( state.isActive) // only for active states
747
+ assert { state !is Finishing } // only for non-finishing states
748
+ assert { state.isActive } // only for active states
752
749
// get state's list or else promote to list to correctly operate on child lists
753
750
val list = getOrPromoteCancellingList(state) ? : return false
754
751
// Create cancelling state (with rootCause!)
@@ -1037,8 +1034,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
1037
1034
// Seals current state and returns list of exceptions
1038
1035
// guarded by `synchronized(this)`
1039
1036
fun sealLocked (proposedException : Throwable ? ): List <Throwable > {
1040
- val eh = _exceptionsHolder // volatile read
1041
- val list = when (eh) {
1037
+ val list = when (val eh = _exceptionsHolder ) { // volatile read
1042
1038
null -> allocateList()
1043
1039
is Throwable -> allocateList().also { it.add(eh) }
1044
1040
is ArrayList <* > -> eh as ArrayList <Throwable >
@@ -1305,14 +1301,15 @@ internal class NodeList : LockFreeLinkedListHead(), Incomplete {
1305
1301
append(" ]" )
1306
1302
}
1307
1303
1308
- override fun toString (): String = getString(" Active" )
1304
+ override fun toString (): String =
1305
+ if (DEBUG ) getString(" Active" ) else super .toString()
1309
1306
}
1310
1307
1311
1308
internal class InactiveNodeList (
1312
1309
override val list : NodeList
1313
1310
) : Incomplete {
1314
1311
override val isActive: Boolean get() = false
1315
- override fun toString (): String = list.getString(" New" )
1312
+ override fun toString (): String = if ( DEBUG ) list.getString(" New" ) else super .toString( )
1316
1313
}
1317
1314
1318
1315
private class InvokeOnCompletion (
@@ -1337,7 +1334,7 @@ private class ResumeAwaitOnCompletion<T>(
1337
1334
) : JobNode<JobSupport>(job) {
1338
1335
override fun invoke (cause : Throwable ? ) {
1339
1336
val state = job.state
1340
- check( state !is Incomplete )
1337
+ assert { state !is Incomplete }
1341
1338
if (state is CompletedExceptionally ) {
1342
1339
// Resume with exception in atomic way to preserve exception
1343
1340
continuation.resumeWithExceptionMode(state.cause, MODE_ATOMIC_DEFAULT )
0 commit comments