blob: 40fcb49ce1766708a4194b8f3117921f5e8d485e [file] [log] [blame]
Roman Elizarovf2239e12018-01-10 16:25:25 +03001/*
2 * Copyright 2016-2017 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package kotlinx.coroutines.experimental
18
Roman Elizarovaa461cf2018-04-11 13:20:29 +030019import kotlinx.coroutines.experimental.internalAnnotations.*
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030020import kotlin.coroutines.experimental.*
Roman Elizarovaa461cf2018-04-11 13:20:29 +030021
Roman Elizarovf2239e12018-01-10 16:25:25 +030022/**
Roman Elizarovf29203c2018-01-11 12:39:36 +030023 * Class for an internal state of a job that had completed exceptionally, including cancellation.
24 *
25 * **Note: This class cannot be used outside of internal coroutines framework**.
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030026 * **Note: cannot be internal until we get rid of MutableDelegateContinuation in IO**
Roman Elizarovf2239e12018-01-10 16:25:25 +030027 *
Vsevolod Tolstopyatov4b9a5592018-04-11 13:17:14 +030028 * @param cause the exceptional completion cause. It's either original exceptional cause
29 * or artificial JobCancellationException if no cause was provided
Roman Elizarovf2239e12018-01-10 16:25:25 +030030 * @suppress **This is unstable API and it is subject to change.**
31 */
Roman Elizarove89cd682018-04-25 13:03:40 +030032open class CompletedExceptionally(
33 @JvmField public val cause: Throwable
Roman Elizarovf2239e12018-01-10 16:25:25 +030034) {
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030035 override fun toString(): String = "$classSimpleName[$cause]"
Roman Elizarovf29203c2018-01-11 12:39:36 +030036}
37
38/**
39 * A specific subclass of [CompletedExceptionally] for cancelled jobs.
40 *
41 * **Note: This class cannot be used outside of internal coroutines framework**.
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030042 * TODO rename to CancelledJob?
43 *
Roman Elizarovf29203c2018-01-11 12:39:36 +030044 * @param job the job that was cancelled.
Vsevolod Tolstopyatov4b9a5592018-04-11 13:17:14 +030045 * @param cause the exceptional completion cause. If `cause` is null, then a [JobCancellationException] is created.
Roman Elizarovf29203c2018-01-11 12:39:36 +030046 * @suppress **This is unstable API and it is subject to change.**
47 */
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030048internal class Cancelled(
Roman Elizarov6d9f40f2018-04-28 14:44:02 +030049 job: Job,
Roman Elizarovf29203c2018-01-11 12:39:36 +030050 cause: Throwable?
Vsevolod Tolstopyatovf5e63ca2018-04-12 19:59:56 +030051) : CompletedExceptionally(cause ?: JobCancellationException("Job was cancelled normally", null, job))
Roman Elizarovf29203c2018-01-11 12:39:36 +030052
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030053/**
54 * A specific subclass of [CompletedExceptionally] for cancelled [AbstractContinuation].
55 *
56 * **Note: This class cannot be used outside of internal coroutines framework**.
57 *
58 * @param continuation the continuation that was cancelled.
59 * @param cause the exceptional completion cause. If `cause` is null, then a [JobCancellationException]
60 * if created on first get from [exception] property.
61 * @suppress **This is unstable API and it is subject to change.**
62 */
63public class CancelledContinuation(
Roman Elizarov6d9f40f2018-04-28 14:44:02 +030064 continuation: Continuation<*>,
Vsevolod Tolstopyatovf3a50132018-04-16 19:41:20 +030065 cause: Throwable?
Roman Elizarov6d9f40f2018-04-28 14:44:02 +030066) : CompletedExceptionally(cause ?: CancellationException("Continuation $continuation was cancelled normally"))