blob: 6f06263a5b8e37b0adc6ca2072e7a249844acf82 [file] [log] [blame]
Roman Elizarovf2239e12018-01-10 16:25:25 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovf2239e12018-01-10 16:25:25 +03003 */
4
5package kotlinx.coroutines.experimental
6
Roman Elizarovaa461cf2018-04-11 13:20:29 +03007import kotlinx.coroutines.experimental.internalAnnotations.*
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +03008import kotlin.coroutines.experimental.*
Roman Elizarovaa461cf2018-04-11 13:20:29 +03009
Roman Elizarovf2239e12018-01-10 16:25:25 +030010/**
Roman Elizarovf29203c2018-01-11 12:39:36 +030011 * Class for an internal state of a job that had completed exceptionally, including cancellation.
12 *
13 * **Note: This class cannot be used outside of internal coroutines framework**.
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030014 * **Note: cannot be internal until we get rid of MutableDelegateContinuation in IO**
Roman Elizarovf2239e12018-01-10 16:25:25 +030015 *
Vsevolod Tolstopyatov4b9a5592018-04-11 13:17:14 +030016 * @param cause the exceptional completion cause. It's either original exceptional cause
17 * or artificial JobCancellationException if no cause was provided
Roman Elizarovf2239e12018-01-10 16:25:25 +030018 * @suppress **This is unstable API and it is subject to change.**
19 */
Roman Elizarove89cd682018-04-25 13:03:40 +030020open class CompletedExceptionally(
21 @JvmField public val cause: Throwable
Roman Elizarovf2239e12018-01-10 16:25:25 +030022) {
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030023 override fun toString(): String = "$classSimpleName[$cause]"
Roman Elizarovf29203c2018-01-11 12:39:36 +030024}
25
26/**
27 * A specific subclass of [CompletedExceptionally] for cancelled jobs.
28 *
29 * **Note: This class cannot be used outside of internal coroutines framework**.
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030030 * TODO rename to CancelledJob?
31 *
Roman Elizarovf29203c2018-01-11 12:39:36 +030032 * @param job the job that was cancelled.
Vsevolod Tolstopyatov4b9a5592018-04-11 13:17:14 +030033 * @param cause the exceptional completion cause. If `cause` is null, then a [JobCancellationException] is created.
Roman Elizarovf29203c2018-01-11 12:39:36 +030034 * @suppress **This is unstable API and it is subject to change.**
35 */
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030036internal class Cancelled(
Roman Elizarov6d9f40f2018-04-28 14:44:02 +030037 job: Job,
Roman Elizarovf29203c2018-01-11 12:39:36 +030038 cause: Throwable?
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030039) : CompletedExceptionally(cause ?: JobCancellationException("Job was cancelled normally", null, job))
Roman Elizarovf29203c2018-01-11 12:39:36 +030040
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030041/**
42 * A specific subclass of [CompletedExceptionally] for cancelled [AbstractContinuation].
43 *
44 * **Note: This class cannot be used outside of internal coroutines framework**.
45 *
46 * @param continuation the continuation that was cancelled.
47 * @param cause the exceptional completion cause. If `cause` is null, then a [JobCancellationException]
48 * if created on first get from [exception] property.
49 * @suppress **This is unstable API and it is subject to change.**
50 */
51public class CancelledContinuation(
Roman Elizarov6d9f40f2018-04-28 14:44:02 +030052 continuation: Continuation<*>,
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030053 cause: Throwable?
Roman Elizarov6d9f40f2018-04-28 14:44:02 +030054) : CompletedExceptionally(cause ?: CancellationException("Continuation $continuation was cancelled normally"))