Skip to content

Commit 90f64e6

Browse files
globstergqwwdfsad
andauthored
Various kotlinlang API module reference improvements (#4167)
* Avoid generating documentation for `runTestCoroutine` * It is marked with `@InternalCoroutinesApi` and is not supposed to be available to the library users. * Update the package descriptions in the documentation * Some packages had no description, and some had outdated ones. * Mention some additional important API entries in the top-level docs * Remove most of the occurrences of InternalCoroutinesApi from docs Co-authored-by: Vsevolod Tolstopyatov <[email protected]>
1 parent 12f36aa commit 90f64e6

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

kotlinx-coroutines-core/README.md

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ Coroutine builder functions:
1313

1414
Coroutine dispatchers implementing [CoroutineDispatcher]:
1515

16-
| **Name** | **Description**
17-
| ------------------------------------------------------------------- | ---------------
18-
| [Dispatchers.Default][kotlinx.coroutines.Dispatchers.Default] | Confines coroutine execution to a shared pool of background threads
19-
| [Dispatchers.Unconfined][kotlinx.coroutines.Dispatchers.Unconfined] | Does not confine coroutine execution in any way
16+
| **Name** | **Description**
17+
| --------------------------------------------------------------------------------------------------- | ---------------
18+
| [Dispatchers.Main][kotlinx.coroutines.Dispatchers.Main] | Confines coroutine execution to the UI thread
19+
| [Dispatchers.Default][kotlinx.coroutines.Dispatchers.Default] | Confines coroutine execution to a shared pool of background threads
20+
| [Dispatchers.Unconfined][kotlinx.coroutines.Dispatchers.Unconfined] | Does not confine coroutine execution in any way
21+
| [CoroutineDispatcher.limitedParallelism][kotlinx.coroutines.CoroutineDispatcher.limitedParallelism] | Creates a view of the given dispatcher, limiting the number of tasks executing in parallel
2022

2123
More context elements:
2224

@@ -27,10 +29,14 @@ More context elements:
2729

2830
Synchronization primitives for coroutines:
2931

30-
| **Name** | **Suspending functions** | **Description**
31-
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ---------------
32-
| [Mutex][kotlinx.coroutines.sync.Mutex] | [lock][kotlinx.coroutines.sync.Mutex.lock] | Mutual exclusion
33-
| [Channel][kotlinx.coroutines.channels.Channel] | [send][kotlinx.coroutines.channels.SendChannel.send], [receive][kotlinx.coroutines.channels.ReceiveChannel.receive] | Communication channel (aka queue or exchanger)
32+
| **Name** | **Suspending functions** | **Description**
33+
|------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| ---------------
34+
| [Mutex][kotlinx.coroutines.sync.Mutex] | [lock][kotlinx.coroutines.sync.Mutex.lock] | Mutual exclusion
35+
| [Semaphore][kotlinx.coroutines.sync.Semaphore] | [acquire][kotlinx.coroutines.sync.Semaphore.acquire] | Limiting the maximum concurrency
36+
| [Channel][kotlinx.coroutines.channels.Channel] | [send][kotlinx.coroutines.channels.SendChannel.send], [receive][kotlinx.coroutines.channels.ReceiveChannel.receive] | Communication channel (aka queue or exchanger)
37+
| [Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/) | [collect][kotlinx.coroutines.flow.Flow.collect] | Asynchronous stream of values
38+
39+
<!--- Flow direct link is here to workaround MD case-insensitivity -->
3440

3541
Top-level suspending functions:
3642

@@ -45,10 +51,27 @@ Top-level suspending functions:
4551
| [joinAll][kotlinx.coroutines.joinAll] | Joins on all given jobs
4652

4753
Cancellation support for user-defined suspending functions is available with [suspendCancellableCoroutine]
48-
helper function. [NonCancellable] job object is provided to suppress cancellation with
54+
helper function.
55+
The [NonCancellable] job object is provided to suppress cancellation inside the
4956
`withContext(NonCancellable) {...}` block of code.
5057

51-
[Select][kotlinx.coroutines.selects.select] expression waits for the result of multiple suspending functions simultaneously:
58+
Ways to construct asynchronous streams of values:
59+
60+
| **Name** | **Type** | **Description**
61+
| --------------------------------------------------------------------- | -------- | ---------------
62+
| [flow][kotlinx.coroutines.flow.flow] | cold | Runs a generator-style block of code that emits values
63+
| [flowOf][kotlinx.coroutines.flow.flowOf] | cold | Emits the values passed as arguments
64+
| [channelFlow][kotlinx.coroutines.flow.channelFlow] | cold | Runs the given code, providing a channel sending to which means emitting from the flow
65+
| [callbackFlow][kotlinx.coroutines.flow.callbackFlow] | cold | Allows transforming a callback-based API into a flow
66+
| [ReceiveChannel.consumeAsFlow][kotlinx.coroutines.flow.consumeAsFlow] | hot | Transforms a channel into a flow, emitting all of the received values to a single subscriber
67+
| [ReceiveChannel.receiveAsFlow][kotlinx.coroutines.flow.receiveAsFlow] | hot | Transforms a channel into a flow, distributing the received values among its subscribers
68+
| [MutableSharedFlow][kotlinx.coroutines.flow.MutableSharedFlow] | hot | Allows emitting each value to arbitrarily many subscribers at once
69+
| [MutableStateFlow][kotlinx.coroutines.flow.MutableStateFlow] | hot | Represents mutable state as a flow
70+
71+
A *cold* stream is some process of generating values, and this process is performed separately for each subscriber.
72+
A *hot* stream uses the same source of values independently of whether there are subscribers.
73+
74+
A [select][kotlinx.coroutines.selects.select] expression waits for the result of multiple suspending functions simultaneously:
5275

5376
| **Receiver** | **Suspending function** | **Select clause** | **Non-suspending version**
5477
| ------------------------------------------------------------ | --------------------------------------------------------------- | ----------------------------------------------------------------- | --------------------------
@@ -65,24 +88,36 @@ General-purpose coroutine builders, contexts, and helper functions.
6588

6689
# Package kotlinx.coroutines.sync
6790

68-
Synchronization primitives (mutex).
91+
Synchronization primitives (mutex and semaphore).
6992

7093
# Package kotlinx.coroutines.channels
7194

7295
Channels &mdash; non-blocking primitives for communicating a stream of elements between coroutines.
7396

7497
# Package kotlinx.coroutines.flow
7598

76-
Flow &mdash; asynchronous cold stream of elements.
99+
Flow &mdash; asynchronous cold and hot streams of elements.
77100

78101
# Package kotlinx.coroutines.selects
79102

80-
Select expression to perform multiple suspending operations simultaneously until one of them succeeds.
103+
Select &mdash; expressions that perform multiple suspending operations simultaneously until one of them succeeds.
81104

82105
# Package kotlinx.coroutines.intrinsics
83106

84107
Low-level primitives for finer-grained control of coroutines.
85108

109+
# Package kotlinx.coroutines.future
110+
111+
[JDK 8's `CompletableFuture`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) support.
112+
113+
# Package kotlinx.coroutines.stream
114+
115+
[JDK 8's `Stream`](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html) support.
116+
117+
# Package kotlinx.coroutines.time
118+
119+
[JDK 8's `Duration`](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html) support via additional overloads for existing time-based operators.
120+
86121
<!--- MODULE kotlinx-coroutines-core -->
87122
<!--- INDEX kotlinx.coroutines -->
88123

@@ -93,8 +128,10 @@ Low-level primitives for finer-grained control of coroutines.
93128
[kotlinx.coroutines.Deferred]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html
94129
[kotlinx.coroutines.runBlocking]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html
95130
[CoroutineDispatcher]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html
131+
[kotlinx.coroutines.Dispatchers.Main]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html
96132
[kotlinx.coroutines.Dispatchers.Default]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html
97133
[kotlinx.coroutines.Dispatchers.Unconfined]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html
134+
[kotlinx.coroutines.CoroutineDispatcher.limitedParallelism]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html
98135
[kotlinx.coroutines.NonCancellable]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable/index.html
99136
[kotlinx.coroutines.CoroutineExceptionHandler]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html
100137
[kotlinx.coroutines.delay]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/delay.html
@@ -112,10 +149,24 @@ Low-level primitives for finer-grained control of coroutines.
112149
[kotlinx.coroutines.Deferred.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html
113150
[kotlinx.coroutines.Deferred.onAwait]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html
114151

152+
<!--- INDEX kotlinx.coroutines.flow -->
153+
154+
[kotlinx.coroutines.flow.Flow.collect]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html
155+
[kotlinx.coroutines.flow.flow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html
156+
[kotlinx.coroutines.flow.flowOf]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-of.html
157+
[kotlinx.coroutines.flow.channelFlow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/channel-flow.html
158+
[kotlinx.coroutines.flow.callbackFlow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/callback-flow.html
159+
[kotlinx.coroutines.flow.consumeAsFlow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/consume-as-flow.html
160+
[kotlinx.coroutines.flow.receiveAsFlow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/receive-as-flow.html
161+
[kotlinx.coroutines.flow.MutableSharedFlow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/index.html
162+
[kotlinx.coroutines.flow.MutableStateFlow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html
163+
115164
<!--- INDEX kotlinx.coroutines.sync -->
116165

117166
[kotlinx.coroutines.sync.Mutex]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html
118167
[kotlinx.coroutines.sync.Mutex.lock]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html
168+
[kotlinx.coroutines.sync.Semaphore]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html
169+
[kotlinx.coroutines.sync.Semaphore.acquire]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/acquire.html
119170

120171
<!--- INDEX kotlinx.coroutines.channels -->
121172

kotlinx-coroutines-core/common/src/selects/Select.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public sealed interface SelectBuilder<in R> {
124124
* 4) the function that specifies how the internal result provided via
125125
* [SelectInstance.trySelect] or [SelectInstance.selectInRegistrationPhase]
126126
* should be processed in case of this `select` cancellation while dispatching.
127+
*
128+
* @suppress **This is unstable API, and it is subject to change.**
127129
*/
128130
@InternalCoroutinesApi
129131
public sealed interface SelectClause {
@@ -138,6 +140,8 @@ public sealed interface SelectClause {
138140
* the specified clause object. In case of channels, the registration logic
139141
* coincides with the plain `send/receive` operation with the only difference that
140142
* the `select` instance is stored as a waiter instead of continuation.
143+
*
144+
* @suppress **This is unstable API, and it is subject to change.**
141145
*/
142146
@InternalCoroutinesApi
143147
public typealias RegistrationFunction = (clauseObject: Any, select: SelectInstance<*>, param: Any?) -> Unit
@@ -147,6 +151,8 @@ public typealias RegistrationFunction = (clauseObject: Any, select: SelectInstan
147151
* or [SelectInstance.trySelect] should be processed. For example, both [ReceiveChannel.onReceive] and
148152
* [ReceiveChannel.onReceiveCatching] clauses perform exactly the same synchronization logic,
149153
* but differ when the channel has been discovered in the closed or cancelled state.
154+
*
155+
* @suppress **This is unstable API, and it is subject to change.**
150156
*/
151157
@InternalCoroutinesApi
152158
public typealias ProcessResultFunction = (clauseObject: Any, param: Any?, clauseResult: Any?) -> Any?
@@ -156,6 +162,8 @@ public typealias ProcessResultFunction = (clauseObject: Any, param: Any?, clause
156162
* or [SelectInstance.selectInRegistrationPhase], should be processed in case of this `select`
157163
* cancellation while dispatching. Unfortunately, we cannot pass this function only in [SelectInstance.trySelect],
158164
* as [SelectInstance.selectInRegistrationPhase] can be called when the coroutine is already cancelled.
165+
*
166+
* @suppress **This is unstable API, and it is subject to change.**
159167
*/
160168
@InternalCoroutinesApi
161169
public typealias OnCancellationConstructor = (select: SelectInstance<*>, param: Any?, internalResult: Any?) ->

kotlinx-coroutines-core/wasmWasi/src/internal/CoroutineRunner.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package kotlinx.coroutines.internal
33
import kotlinx.coroutines.*
44
import kotlin.coroutines.*
55

6+
/** @suppress **This is internal API and it is subject to change.** */
67
@InternalCoroutinesApi
78
public fun runTestCoroutine(context: CoroutineContext, block: suspend CoroutineScope.() -> Unit) {
89
val newContext = GlobalScope.newCoroutineContext(context)
@@ -11,4 +12,4 @@ public fun runTestCoroutine(context: CoroutineContext, block: suspend CoroutineS
1112
runEventLoop()
1213
check(coroutine.isCompleted) { "Coroutine $coroutine did not complete, but the system reached quiescence" }
1314
coroutine.getCompletionExceptionOrNull()?.let { throw it }
14-
}
15+
}

0 commit comments

Comments
 (0)