|
1 |
| -# Coroutines core for Kotlin/JVM |
| 1 | +# Module kotlinx-coroutines-core |
2 | 2 |
|
3 |
| -This directory contains modules that provide core coroutines support on Kotlin/JVM. |
4 |
| -Module name below corresponds to the artifact name in Maven/Gradle. |
| 3 | +Core primitives to work with coroutines, available on all platforms. |
5 | 4 |
|
6 |
| -## Modules |
| 5 | +Coroutine builder functions: |
7 | 6 |
|
8 |
| -* [kotlinx-coroutines-core](kotlinx-coroutines-core/README.md) — core coroutine builders and synchronization primitives. |
9 |
| -* [kotlinx-coroutines-debug](kotlinx-coroutines-debug/README.md) — coroutines debug utilities. |
10 |
| -* [kotlinx-coroutines-test](kotlinx-coroutines-test/README.md) — coroutines test utilities. |
| 7 | +| **Name** | **Result** | **Scope** | **Description** |
| 8 | +| ------------- | ------------- | ---------------- | --------------- |
| 9 | +| [launch] | [Job] | [CoroutineScope] | Launches coroutine that does not have any result |
| 10 | +| [async] | [Deferred] | [CoroutineScope] | Returns a single value with the future result |
| 11 | +| [produce][kotlinx.coroutines.channels.produce] | [ReceiveChannel][kotlinx.coroutines.channels.ReceiveChannel] | [ProducerScope][kotlinx.coroutines.channels.ProducerScope] | Produces a stream of elements |
| 12 | +| [runBlocking] | `T` | [CoroutineScope] | Blocks the thread while the coroutine runs |
11 | 13 |
|
| 14 | +Coroutine dispatchers implementing [CoroutineDispatcher]: |
| 15 | + |
| 16 | +| **Name** | **Description** |
| 17 | +| --------------------------- | --------------- |
| 18 | +| [Dispatchers.Default] | Confines coroutine execution to a shared pool of background threads |
| 19 | +| [Dispatchers.Unconfined] | Does not confine coroutine execution in any way |
| 20 | + |
| 21 | +More context elements: |
| 22 | + |
| 23 | +| **Name** | **Description** |
| 24 | +| --------------------------- | --------------- |
| 25 | +| [NonCancellable] | A non-cancelable job that is always active |
| 26 | +| [CoroutineExceptionHandler] | Handler for uncaught exception |
| 27 | + |
| 28 | +Synchronization primitives for coroutines: |
| 29 | + |
| 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) |
| 34 | + |
| 35 | +Top-level suspending functions: |
| 36 | + |
| 37 | +| **Name** | **Description** |
| 38 | +| ------------------- | --------------- |
| 39 | +| [delay] | Non-blocking sleep |
| 40 | +| [yield] | Yields thread in single-threaded dispatchers |
| 41 | +| [withContext] | Switches to a different context |
| 42 | +| [withTimeout] | Set execution time-limit with exception on timeout |
| 43 | +| [withTimeoutOrNull] | Set execution time-limit will null result on timeout |
| 44 | +| [awaitAll] | Awaits for successful completion of all given jobs or exceptional completion of any |
| 45 | +| [joinAll] | Joins on all given jobs |
| 46 | + |
| 47 | +Cancellation support for user-defined suspending functions is available with [suspendCancellableCoroutine] |
| 48 | +helper function. [NonCancellable] job object is provided to suppress cancellation with |
| 49 | +`withContext(NonCancellable) {...}` block of code. |
| 50 | + |
| 51 | +[Select][kotlinx.coroutines.selects.select] expression waits for the result of multiple suspending functions simultaneously: |
| 52 | + |
| 53 | +| **Receiver** | **Suspending function** | **Select clause** | **Non-suspending version** |
| 54 | +| ---------------- | --------------------------------------------- | ------------------------------------------------ | -------------------------- |
| 55 | +| [Job] | [join][Job.join] | [onJoin][Job.onJoin] | [isCompleted][Job.isCompleted] |
| 56 | +| [Deferred] | [await][Deferred.await] | [onAwait][Deferred.onAwait] | [isCompleted][Job.isCompleted] |
| 57 | +| [SendChannel][kotlinx.coroutines.channels.SendChannel] | [send][kotlinx.coroutines.channels.SendChannel.send] | [onSend][kotlinx.coroutines.channels.SendChannel.onSend] | [offer][kotlinx.coroutines.channels.SendChannel.offer] |
| 58 | +| [ReceiveChannel][kotlinx.coroutines.channels.ReceiveChannel] | [receive][kotlinx.coroutines.channels.ReceiveChannel.receive] | [onReceive][kotlinx.coroutines.channels.ReceiveChannel.onReceive] | [poll][kotlinx.coroutines.channels.ReceiveChannel.poll] |
| 59 | +| [ReceiveChannel][kotlinx.coroutines.channels.ReceiveChannel] | [receiveOrNull][kotlinx.coroutines.channels.ReceiveChannel.receiveOrNull] | [onReceiveOrNull][kotlinx.coroutines.channels.ReceiveChannel.onReceiveOrNull] | [poll][kotlinx.coroutines.channels.ReceiveChannel.poll] |
| 60 | +| [Mutex][kotlinx.coroutines.sync.Mutex] | [lock][kotlinx.coroutines.sync.Mutex.lock] | [onLock][kotlinx.coroutines.sync.Mutex.onLock] | [tryLock][kotlinx.coroutines.sync.Mutex.tryLock] |
| 61 | +| none | [delay] | [onTimeout][kotlinx.coroutines.selects.SelectBuilder.onTimeout] | none |
| 62 | + |
| 63 | +# Package kotlinx.coroutines |
| 64 | + |
| 65 | +General-purpose coroutine builders, contexts, and helper functions. |
| 66 | + |
| 67 | +# Package kotlinx.coroutines.sync |
| 68 | + |
| 69 | +Synchronization primitives (mutex). |
| 70 | + |
| 71 | +# Package kotlinx.coroutines.channels |
| 72 | + |
| 73 | +Channels -- non-blocking primitives for communicating a stream of elements between coroutines. |
| 74 | + |
| 75 | +# Package kotlinx.coroutines.selects |
| 76 | + |
| 77 | +Select expression to perform multiple suspending operations simultaneously until one of them succeeds. |
| 78 | + |
| 79 | +# Package kotlinx.coroutines.intrinsics |
| 80 | + |
| 81 | +Low-level primitives for finer-grained control of coroutines. |
| 82 | + |
| 83 | +# Package kotlinx.coroutines.timeunit |
| 84 | + |
| 85 | +Optional time unit support for multiplatform projects. |
| 86 | + |
| 87 | +# Package kotlinx.coroutines.test |
| 88 | + |
| 89 | +Components to ease writing unit-tests for code that contains coroutines with delays and timeouts. |
| 90 | + |
| 91 | +<!--- MODULE kotlinx-coroutines-core --> |
| 92 | +<!--- INDEX kotlinx.coroutines --> |
| 93 | +[launch]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/launch.html |
| 94 | +[Job]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html |
| 95 | +[CoroutineScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html |
| 96 | +[async]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/async.html |
| 97 | +[Deferred]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html |
| 98 | +[runBlocking]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html |
| 99 | +[CoroutineDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html |
| 100 | +[Dispatchers.Default]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html |
| 101 | +[Dispatchers.Unconfined]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html |
| 102 | +[NonCancellable]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable.html |
| 103 | +[CoroutineExceptionHandler]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html |
| 104 | +[delay]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/delay.html |
| 105 | +[yield]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/yield.html |
| 106 | +[withContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html |
| 107 | +[withTimeout]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html |
| 108 | +[withTimeoutOrNull]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout-or-null.html |
| 109 | +[awaitAll]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/await-all.html |
| 110 | +[joinAll]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/join-all.html |
| 111 | +[suspendCancellableCoroutine]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html |
| 112 | +[Job.join]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/join.html |
| 113 | +[Job.onJoin]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/on-join.html |
| 114 | +[Job.isCompleted]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-completed.html |
| 115 | +[Deferred.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html |
| 116 | +[Deferred.onAwait]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html |
| 117 | +<!--- INDEX kotlinx.coroutines.sync --> |
| 118 | +[kotlinx.coroutines.sync.Mutex]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html |
| 119 | +[kotlinx.coroutines.sync.Mutex.lock]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html |
| 120 | +[kotlinx.coroutines.sync.Mutex.onLock]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/on-lock.html |
| 121 | +[kotlinx.coroutines.sync.Mutex.tryLock]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html |
| 122 | +<!--- INDEX kotlinx.coroutines.channels --> |
| 123 | +[kotlinx.coroutines.channels.produce]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html |
| 124 | +[kotlinx.coroutines.channels.ReceiveChannel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/index.html |
| 125 | +[kotlinx.coroutines.channels.ProducerScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/index.html |
| 126 | +[kotlinx.coroutines.channels.Channel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html |
| 127 | +[kotlinx.coroutines.channels.SendChannel.send]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/send.html |
| 128 | +[kotlinx.coroutines.channels.ReceiveChannel.receive]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive.html |
| 129 | +[kotlinx.coroutines.channels.SendChannel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/index.html |
| 130 | +[kotlinx.coroutines.channels.SendChannel.onSend]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/on-send.html |
| 131 | +[kotlinx.coroutines.channels.SendChannel.offer]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/offer.html |
| 132 | +[kotlinx.coroutines.channels.ReceiveChannel.onReceive]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive.html |
| 133 | +[kotlinx.coroutines.channels.ReceiveChannel.poll]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/poll.html |
| 134 | +[kotlinx.coroutines.channels.ReceiveChannel.receiveOrNull]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive-or-null.html |
| 135 | +[kotlinx.coroutines.channels.ReceiveChannel.onReceiveOrNull]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive-or-null.html |
| 136 | +<!--- INDEX kotlinx.coroutines.selects --> |
| 137 | +[kotlinx.coroutines.selects.select]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html |
| 138 | +[kotlinx.coroutines.selects.SelectBuilder.onTimeout]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/on-timeout.html |
| 139 | +<!--- INDEX kotlinx.coroutines.test --> |
| 140 | +<!--- END --> |
0 commit comments