Roman Elizarov | f2239e1 | 2018-01-10 16:25:25 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | f2239e1 | 2018-01-10 16:25:25 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental |
| 6 | |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 7 | import kotlinx.coroutines.experimental.internalAnnotations.* |
Vsevolod Tolstopyatov | f3a5013 | 2018-04-16 19:41:20 +0300 | [diff] [blame] | 8 | import kotlin.coroutines.experimental.* |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 9 | |
Roman Elizarov | f2239e1 | 2018-01-10 16:25:25 +0300 | [diff] [blame] | 10 | /** |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 11 | * 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 Tolstopyatov | f5e63ca | 2018-04-12 19:59:56 +0300 | [diff] [blame] | 14 | * **Note: cannot be internal until we get rid of MutableDelegateContinuation in IO** |
Roman Elizarov | f2239e1 | 2018-01-10 16:25:25 +0300 | [diff] [blame] | 15 | * |
Vsevolod Tolstopyatov | 4b9a559 | 2018-04-11 13:17:14 +0300 | [diff] [blame] | 16 | * @param cause the exceptional completion cause. It's either original exceptional cause |
| 17 | * or artificial JobCancellationException if no cause was provided |
Roman Elizarov | f2239e1 | 2018-01-10 16:25:25 +0300 | [diff] [blame] | 18 | * @suppress **This is unstable API and it is subject to change.** |
| 19 | */ |
Roman Elizarov | e89cd68 | 2018-04-25 13:03:40 +0300 | [diff] [blame] | 20 | open class CompletedExceptionally( |
| 21 | @JvmField public val cause: Throwable |
Roman Elizarov | f2239e1 | 2018-01-10 16:25:25 +0300 | [diff] [blame] | 22 | ) { |
Vsevolod Tolstopyatov | f5e63ca | 2018-04-12 19:59:56 +0300 | [diff] [blame] | 23 | override fun toString(): String = "$classSimpleName[$cause]" |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 24 | } |
| 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 Tolstopyatov | f3a5013 | 2018-04-16 19:41:20 +0300 | [diff] [blame] | 30 | * TODO rename to CancelledJob? |
| 31 | * |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 32 | * @param job the job that was cancelled. |
Vsevolod Tolstopyatov | 4b9a559 | 2018-04-11 13:17:14 +0300 | [diff] [blame] | 33 | * @param cause the exceptional completion cause. If `cause` is null, then a [JobCancellationException] is created. |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 34 | * @suppress **This is unstable API and it is subject to change.** |
| 35 | */ |
Vsevolod Tolstopyatov | f5e63ca | 2018-04-12 19:59:56 +0300 | [diff] [blame] | 36 | internal class Cancelled( |
Roman Elizarov | 6d9f40f | 2018-04-28 14:44:02 +0300 | [diff] [blame] | 37 | job: Job, |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 38 | cause: Throwable? |
Vsevolod Tolstopyatov | f5e63ca | 2018-04-12 19:59:56 +0300 | [diff] [blame] | 39 | ) : CompletedExceptionally(cause ?: JobCancellationException("Job was cancelled normally", null, job)) |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 40 | |
Vsevolod Tolstopyatov | f3a5013 | 2018-04-16 19:41:20 +0300 | [diff] [blame] | 41 | /** |
| 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 | */ |
| 51 | public class CancelledContinuation( |
Roman Elizarov | 6d9f40f | 2018-04-28 14:44:02 +0300 | [diff] [blame] | 52 | continuation: Continuation<*>, |
Vsevolod Tolstopyatov | f3a5013 | 2018-04-16 19:41:20 +0300 | [diff] [blame] | 53 | cause: Throwable? |
Roman Elizarov | 6d9f40f | 2018-04-28 14:44:02 +0300 | [diff] [blame] | 54 | ) : CompletedExceptionally(cause ?: CancellationException("Continuation $continuation was cancelled normally")) |