blob: 875574a40976f00b7f6904044f0402a44fb70f84 [file] [log] [blame]
Roman Elizarov9fe5f462018-02-21 19:05:52 +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
19import kotlin.coroutines.experimental.*
20import kotlin.internal.*
21
22/**
23 * Receiver interface for generic coroutine builders, so that the code inside coroutine has a convenient
24 * and fast access to its own cancellation status via [isActive].
25 */
26public interface CoroutineScope {
27 /**
28 * Returns `true` when this coroutine is still active (has not completed and was not cancelled yet).
29 *
30 * Check this property in long-running computation loops to support cancellation:
31 * ```
32 * while (isActive) {
33 * // do some computation
34 * }
35 * ```
36 *
37 * This property is a shortcut for `coroutineContext.isActive` in the scope when
38 * [CoroutineScope] is available.
39 * See [coroutineContext][kotlin.coroutines.experimental.coroutineContext],
40 * [isActive][kotlinx.coroutines.experimental.isActive] and [Job.isActive].
41 */
42 public val isActive: Boolean
43
44 /**
45 * Returns the context of this coroutine.
46 *
47 * @suppress: **Deprecated**: Replaced with top-level [kotlin.coroutines.experimental.coroutineContext].
48 */
49 @Deprecated("Replace with top-level coroutineContext",
50 replaceWith = ReplaceWith("coroutineContext",
51 imports = ["kotlin.coroutines.experimental.coroutineContext"]))
52 @LowPriorityInOverloadResolution
53 @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
54 public val coroutineContext: CoroutineContext
55}