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