Skip to content

Commit d164f73

Browse files
committed
MPP: Common CoroutineContext extensions & doc suppress
1 parent cbb602d commit d164f73

File tree

6 files changed

+37
-5
lines changed
  • common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental
  • core/kotlinx-coroutines-core
  • js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental

6 files changed

+37
-5
lines changed

common/kotlinx-coroutines-core-common/src/main/kotlin/kotlinx/coroutines/experimental/CommonJob.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public expect class JobCancellationException(
5757
val job: Job
5858
}
5959

60+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
61+
public expect fun CoroutineContext.cancel(cause: Throwable? = null): Boolean
62+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
63+
public expect fun CoroutineContext.cancelChildren(cause: Throwable? = null)
64+
6065
public expect fun Job.disposeOnCompletion(handle: DisposableHandle): DisposableHandle
6166
public expect suspend fun Job.cancelAndJoin()
6267
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER", "EXTENSION_SHADOWED_BY_MEMBER") // See KT-21598

core/kotlinx-coroutines-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Module kotlinx-coroutines-core
22

3-
Core primitives to work with coroutines on Kotlin/JVM.
3+
Core primitives to work with coroutines.
44

55
Coroutine builder functions:
66

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public suspend fun delay(time: Long, unit: TimeUnit = TimeUnit.MILLISECONDS) {
111111

112112
/**
113113
* An implementation of [DisposableHandle] that cancels the specified future on dispose.
114+
* @suppress **This is unstable API and it is subject to change.**
114115
*/
115116
public class DisposableFutureHandle(private val future: Future<*>) : DisposableHandle {
116117
override fun dispose() {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,15 @@ public actual suspend fun Job.joinChildren() {
509509
* cancelled as a result of this invocation and `false` if there is no job in the context or if it was already
510510
* cancelled or completed. See [Job.cancel] for details.
511511
*/
512-
public fun CoroutineContext.cancel(cause: Throwable? = null): Boolean =
512+
public actual fun CoroutineContext.cancel(cause: Throwable? = null): Boolean =
513513
this[Job]?.cancel(cause) ?: false
514514

515515
/**
516516
* Cancels all children of the [Job] in this context with an optional cancellation [cause].
517517
* It does not do anything if there is no job in the context or it has no children.
518518
* See [Job.cancelChildren] for details.
519519
*/
520-
public fun CoroutineContext.cancelChildren(cause: Throwable? = null) {
520+
public actual fun CoroutineContext.cancelChildren(cause: Throwable? = null) {
521521
this[Job]?.cancelChildren(cause)
522522
}
523523

@@ -530,6 +530,7 @@ public suspend fun Job.join() = this.join()
530530

531531
/**
532532
* No-op implementation of [Job.Registration].
533+
* @suppress: **Deprecated**: Replace with [NonDisposableHandle]
533534
*/
534535
@Deprecated(message = "Replace with `NonDisposableHandle`",
535536
replaceWith = ReplaceWith("NonDisposableHandle"))
@@ -1170,7 +1171,7 @@ public open class JobSupport(active: Boolean) : Job, SelectClause0, SelectClause
11701171
protected open fun afterCompletion(state: Any?, mode: Int) {}
11711172

11721173
// for nicer debugging
1173-
override final fun toString(): String =
1174+
final override fun toString(): String =
11741175
"${nameString()}{${stateString()}}@$hexAddress"
11751176

11761177
/**
@@ -1400,7 +1401,7 @@ internal abstract class JobNode<out J : Job>(
14001401
final override val isActive: Boolean get() = true
14011402
final override val list: JobSupport.NodeList? get() = null
14021403
final override fun dispose() = (job as JobSupport).removeNode(this)
1403-
override abstract fun invoke(reason: Throwable?)
1404+
abstract override fun invoke(reason: Throwable?)
14041405
}
14051406

14061407
private class InvokeOnCompletion(

js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ private fun IllegalStateException(message: String, cause: Throwable?) =
306306
private fun String.withCause(cause: Throwable?) =
307307
if (cause == null) this else "$this; caused by $cause"
308308

309+
// -------------------- CoroutineContext extensions --------------------
310+
311+
/**
312+
* Cancels [Job] of this context with an optional cancellation [cause]. The result is `true` if the job was
313+
* cancelled as a result of this invocation and `false` if there is no job in the context or if it was already
314+
* cancelled or completed. See [Job.cancel] for details.
315+
*/
316+
public actual fun CoroutineContext.cancel(cause: Throwable? = null): Boolean =
317+
this[Job]?.cancel(cause) ?: false
318+
319+
/**
320+
* Cancels all children of the [Job] in this context with an optional cancellation [cause].
321+
* It does not do anything if there is no job in the context or it has no children.
322+
* See [Job.cancelChildren] for details.
323+
*/
324+
public actual fun CoroutineContext.cancelChildren(cause: Throwable? = null) {
325+
this[Job]?.cancelChildren(cause)
326+
}
327+
309328
// -------------------- Job extensions --------------------
310329

311330
/**

js/kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental/internal/LinkedList.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package kotlinx.coroutines.experimental.internal
1818

1919
private typealias Node = LinkedListNode
2020

21+
/**
22+
* @suppress **This is unstable API and it is subject to change.**
23+
*/
2124
public open class LinkedListNode {
2225
public var next = this
2326
private set
@@ -46,6 +49,9 @@ public open class LinkedListNode {
4649
}
4750
}
4851

52+
/**
53+
* @suppress **This is unstable API and it is subject to change.**
54+
*/
4955
public open class LinkedListHead : LinkedListNode() {
5056
public val isEmpty get() = next === this
5157

0 commit comments

Comments
 (0)