Roman Elizarov | 9fe5f46 | 2018-02-21 19:05:52 +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 | 9fe5f46 | 2018-02-21 19:05:52 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental |
| 6 | |
| 7 | import kotlin.coroutines.experimental.* |
| 8 | import 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 | */ |
| 14 | public 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 | } |