Skip to content

Commit 2a4fb06

Browse files
committed
MPP: Job.getCancellationException docs & proper Throwable.cause override
1 parent a12ee15 commit 2a4fb06

File tree

1 file changed

+12
-10
lines changed
  • js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental

1 file changed

+12
-10
lines changed

js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,18 @@ public actual interface Job : CoroutineContext.Element {
8787
public actual val isCancelled: Boolean
8888

8989
/**
90-
* Returns [CancellationException] that signals the completion of this job.
90+
* Returns [CancellationException] that signals the completion of this job. This function is
91+
* used by [cancellable][suspendCancellableCoroutine] suspending functions. They throw exception
92+
* returned by this function when they suspend in the context of this job and this job becomes _complete_.
9193
*
92-
* It returns the original [cancel] cause if it is an instance of [CancellationException] or
93-
* an instance of [JobCancellationException] if this job was cancelled with a cause of
94-
* different type, was cancelled without a cause or had completed normally.
94+
* This function returns the original [cancel] cause of this job if that `cause` was an instance of
95+
* [CancellationException]. Otherwise (if this job was cancelled with a cause of a different type, or
96+
* was cancelled without a cause, or had completed normally), an instance of [JobCancellationException] is
97+
* returned. The [JobCancellationException.cause] of the resulting [JobCancellationException] references
98+
* the original cancellation cause that was passed to [cancel] function.
9599
*
96-
* This function throws [IllegalStateException] when invoked for an job that has not
100+
* This function throws [IllegalStateException] when invoked on a job that has not
97101
* [completed][isCompleted] nor [cancelled][isCancelled] yet.
98-
*
99-
* The [cancellable][suspendCancellableCoroutine] suspending functions throw this exception
100-
* when trying to suspend in the context of this job.
101102
*/
102103
public actual fun getCancellationException(): CancellationException
103104

@@ -255,7 +256,8 @@ public actual interface DisposableHandle {
255256
* This exception gets thrown if an exception is caught while processing [CompletionHandler] invocation for [Job].
256257
*/
257258
public actual class CompletionHandlerException public actual constructor(
258-
message: String, cause: Throwable
259+
message: String,
260+
public override val cause: Throwable
259261
) : RuntimeException(message.withCause(cause))
260262

261263
public actual open class CancellationException actual constructor(message: String) : IllegalStateException(message)
@@ -267,7 +269,7 @@ public actual open class CancellationException actual constructor(message: Strin
267269
*/
268270
public actual class JobCancellationException public actual constructor(
269271
message: String,
270-
cause: Throwable?,
272+
public override val cause: Throwable?,
271273
/**
272274
* The job that was cancelled.
273275
*/

0 commit comments

Comments
 (0)