Skip to content

Commit 834af46

Browse files
committed
Introduced CancellableContinuation.isCancelled
1 parent 67891d8 commit 834af46

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CancellableContinuation.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import kotlin.coroutines.suspendCoroutine
1313
* If the cancel reason was not a [CancellationException], then the original exception is added as cause of the
1414
* [CancellationException] that this continuation resumes with.
1515
*/
16-
public interface CancellableContinuation<in T> : Continuation<T>, Job
16+
public interface CancellableContinuation<in T> : Continuation<T>, Job {
17+
/**
18+
* Returns `true` if this continuation was cancelled. It implies that [isActive] is `false`.
19+
*/
20+
val isCancelled: Boolean
21+
}
1722

1823
/**
1924
* Suspend coroutine similar to [suspendCoroutine], but provide an implementation of [CancellableContinuation] to
@@ -56,6 +61,9 @@ internal class SafeCancellableContinuation<in T>(
5661
return state
5762
}
5863

64+
override val isCancelled: Boolean
65+
get() = getState() is Cancelled
66+
5967
@Suppress("UNCHECKED_CAST")
6068
override fun afterCompletion(state: Any?) {
6169
if (suspendedThread === Thread.currentThread()) {

0 commit comments

Comments
 (0)