@@ -57,7 +57,7 @@ public interface Job : CoroutineContext.Element {
57
57
public fun onCompletion (handler : CompletionHandler ): Registration
58
58
59
59
/* *
60
- * Cancel this activity with an optional cancellation [reason ]. The result is `true` if this job was
60
+ * Cancel this activity with an optional cancellation [cause ]. The result is `true` if this job was
61
61
* cancelled as a result of this invocation and `false` otherwise
62
62
* (if it was already cancelled or it is [NonCancellable]).
63
63
* Repeated invocation of this function has no effect and always produces `false`.
@@ -66,7 +66,7 @@ public interface Job : CoroutineContext.Element {
66
66
* at the corresponding original cancellation site and passed into this method to aid in debugging by providing
67
67
* both the context of cancellation and text description of the reason.
68
68
*/
69
- public fun cancel (reason : Throwable ? = null): Boolean
69
+ public fun cancel (cause : Throwable ? = null): Boolean
70
70
71
71
@Suppress(" DeprecatedCallableAddReplaceWith" )
72
72
@Deprecated(message = " Operator '+' on two Job objects is meaningless. " +
@@ -231,7 +231,7 @@ internal open class JobSupport : AbstractCoroutineContextElement(Job), Job {
231
231
232
232
fun completeUpdateState (expect : Any , update : Any? ) {
233
233
// #3. Invoke completion handlers
234
- val reason = (update as ? CompletedExceptionally )?.cancelReason
234
+ val reason = (update as ? CompletedExceptionally )?.cancelCause
235
235
var completionException: Throwable ? = null
236
236
when (expect) {
237
237
// SINGLE/SINGLE+ state -- one completion handler (common case)
@@ -295,7 +295,7 @@ internal open class JobSupport : AbstractCoroutineContextElement(Job), Job {
295
295
}
296
296
// is not active anymore
297
297
else -> {
298
- handler((state as ? Cancelled )?.cancelReason )
298
+ handler((state as ? Cancelled )?.cancelCause )
299
299
return EmptyRegistration
300
300
}
301
301
}
@@ -327,10 +327,10 @@ internal open class JobSupport : AbstractCoroutineContextElement(Job), Job {
327
327
}
328
328
}
329
329
330
- final override fun cancel (reason : Throwable ? ): Boolean {
330
+ final override fun cancel (cause : Throwable ? ): Boolean {
331
331
while (true ) { // lock-free loop on state
332
332
val state = this .state as ? Active ? : return false // quit if not active anymore
333
- if (updateState(state, Cancelled (reason ))) return true
333
+ if (updateState(state, Cancelled (cause ))) return true
334
334
}
335
335
}
336
336
@@ -371,31 +371,31 @@ internal open class JobSupport : AbstractCoroutineContextElement(Job), Job {
371
371
* Abstract class for a [state][getState] of a job that had completed exceptionally, including cancellation.
372
372
*/
373
373
internal abstract class CompletedExceptionally {
374
- abstract val cancelReason : Throwable // original reason or fresh CancellationException
374
+ abstract val cancelCause : Throwable // original reason or fresh CancellationException
375
375
abstract val exception: Throwable // the exception to be thrown in continuation
376
376
377
- // convert cancelReason to CancellationException on first need
377
+ // convert cancelCause to CancellationException on first need
378
378
@Volatile
379
379
private var _cancellationException : CancellationException ? = null
380
380
381
381
val cancellationException: CancellationException get() =
382
382
_cancellationException ? : // atomic read volatile var or else build new
383
- (cancelReason as ? CancellationException ? :
384
- CancellationException (cancelReason .message). apply { initCause(cancelReason) } )
385
- . also { _cancellationException = it }
386
-
383
+ (cancelCause as ? CancellationException ? :
384
+ CancellationException (cancelCause .message)
385
+ . apply { initCause(cancelCause) })
386
+ . also { _cancellationException = it }
387
387
}
388
388
389
389
/* *
390
390
* Represents a [state][getState] of a cancelled job.
391
391
*/
392
- internal class Cancelled (specifiedReason : Throwable ? ) : CompletedExceptionally() {
392
+ internal class Cancelled (specifiedCause : Throwable ? ) : CompletedExceptionally() {
393
393
@Volatile
394
- private var _cancelReason = specifiedReason // materialize CancellationException on first need
394
+ private var _cancelCause = specifiedCause // materialize CancellationException on first need
395
395
396
- override val cancelReason : Throwable get() =
397
- _cancelReason ? : // atomic read volatile var or else create new
398
- CancellationException (" Job was cancelled without specified reason " ).also { _cancelReason = it }
396
+ override val cancelCause : Throwable get() =
397
+ _cancelCause ? : // atomic read volatile var or else create new
398
+ CancellationException (" Job was cancelled" ).also { _cancelCause = it }
399
399
400
400
override val exception: Throwable get() = cancellationException
401
401
}
@@ -404,7 +404,7 @@ internal open class JobSupport : AbstractCoroutineContextElement(Job), Job {
404
404
* Represents a [state][getState] of a failed job.
405
405
*/
406
406
internal class Failed (override val exception : Throwable ) : CompletedExceptionally() {
407
- override val cancelReason : Throwable get() = exception
407
+ override val cancelCause : Throwable get() = exception
408
408
}
409
409
}
410
410
0 commit comments