|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| benchmarks/ | | 03-May-2024 | - | 3,589 | 2,638 |
| binary-compatibility-validator/ | | 03-May-2024 | - | 3,512 | 2,673 |
| docs/ | | 03-May-2024 | - | 6,494 | 4,548 |
| gradle/ | | 03-May-2024 | - | 685 | 572 |
| integration/ | | 03-May-2024 | - | 3,303 | 2,405 |
| js/ | | 03-May-2024 | - | 418 | 328 |
| knit/ | | 03-May-2024 | - | 649 | 569 |
| kotlinx-coroutines-bom/ | | 03-May-2024 | - | 25 | 22 |
| kotlinx-coroutines-core/ | | 03-May-2024 | - | 55,937 | 38,032 |
| kotlinx-coroutines-debug/ | | 03-May-2024 | - | 2,421 | 1,762 |
| kotlinx-coroutines-test/ | | 03-May-2024 | - | 2,114 | 1,483 |
| license/ | | 03-May-2024 | - | 30 | 24 |
| publication-validator/ | | 03-May-2024 | - | 447 | 343 |
| reactive/ | | 03-May-2024 | - | 8,935 | 6,645 |
| site/ | | 03-May-2024 | - | 772 | 593 |
| stdlib-stubs/ | | 03-May-2024 | - | 91 | 61 |
| ui/ | | 03-May-2024 | - | 4,903 | 3,715 |
| .gitignore | D | 03-May-2024 | 74 | 8 | 8 |
| CHANGES.md | D | 03-May-2024 | 63.6 KiB | 952 | 813 |
| CODE_OF_CONDUCT.md | D | 03-May-2024 | 269 | 5 | 2 |
| LICENSE | D | 03-May-2024 | 11.1 KiB | 203 | 169 |
| LICENSE.txt | D | 03-May-2024 | 557 | 13 | 10 |
| METADATA | D | 03-May-2024 | 258 | 13 | 11 |
| MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | | |
| NOTICE | D | 03-May-2024 | 11.1 KiB | 203 | 169 |
| README.md | D | 03-May-2024 | 16.6 KiB | 292 | 236 |
| RELEASE.md | D | 03-May-2024 | 3.1 KiB | 81 | 58 |
| build.gradle | D | 03-May-2024 | 9.9 KiB | 248 | 210 |
| bump-version.sh | D | 03-May-2024 | 1.1 KiB | 37 | 29 |
| coroutines-guide.md | D | 03-May-2024 | 12.1 KiB | 121 | 118 |
| gradle.properties | D | 03-May-2024 | 771 | 34 | 29 |
| gradlew | D | 03-May-2024 | 5.2 KiB | 173 | 128 |
| gradlew.bat | D | 03-May-2024 | 2.1 KiB | 85 | 61 |
| settings.gradle | D | 03-May-2024 | 1.2 KiB | 48 | 35 |
README.md
1# kotlinx.coroutines
2
3[![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
4[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)
5[![Download](https://api.bintray.com/packages/kotlin/kotlinx/kotlinx.coroutines/images/download.svg?version=1.3.1) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.3.1)
6
7Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
8This is a companion version for Kotlin `1.3.50` release.
9
10```kotlin
11suspend fun main() = coroutineScope {
12 launch {
13 delay(1000)
14 println("Kotlin Coroutines World!")
15 }
16 println("Hello")
17}
18```
19
20> Play with coroutines online [here](https://pl.kotl.in/hG_tKbid_)
21
22## Modules
23
24* [core](kotlinx-coroutines-core/README.md) — common coroutines across all platforms:
25 * [launch] and [async] coroutine builders returning [Job] and [Deferred] light-weight futures with cancellation support;
26 * [Dispatchers] object with [Main][Dispatchers.Main] dispatcher for Android/Swing/JavaFx, and [Default][Dispatchers.Default] dispatcher for background coroutines;
27 * [delay] and [yield] top-level suspending functions;
28 * [Flow] — cold asynchronous stream with [flow][_flow] builder and comprehensive operator set ([filter], [map], etc);
29 * [Channel], [Mutex], and [Semaphore] communication and synchronization primitives;
30 * [coroutineScope], [supervisorScope], [withContext], and [withTimeout] scope builders;
31 * [MainScope()] for Android and UI applications;
32 * [SupervisorJob()] and [CoroutineExceptionHandler] for supervision of coroutines hierarchies;
33 * [select] expression support and more.
34* [core/jvm](kotlinx-coroutines-core/jvm/) — additional core features available on Kotlin/JVM:
35 * [Dispatchers.IO] dispatcher for blocking coroutines;
36 * [Executor.asCoroutineDispatcher] extension, custom thread pools, and more.
37* [core/js](kotlinx-coroutines-core/js/) — additional core features available on Kotlin/JS:
38 * Integration with `Promise` via [Promise.await] and [promise] builder;
39 * Integration with `Window` via [Window.asCoroutineDispatcher], etc.
40* [test](kotlinx-coroutines-test/README.md) — test utilities for coroutines:
41 * [Dispatchers.setMain] to override [Dispatchers.Main] in tests;
42 * [TestCoroutineScope] to test suspending functions and coroutines.
43* [debug](kotlinx-coroutines-debug/README.md) — debug utilities for coroutines:
44 * [DebugProbes] API to probe, keep track of, print and dump active coroutines;
45 * [CoroutinesTimeout] test rule to automatically dump coroutines on test timeout.
46* [reactive](reactive/README.md) — modules that provide builders and iteration support for various reactive streams libraries:
47 * Reactive Streams ([Publisher.collect], [Publisher.awaitSingle], [publish], etc),
48 RxJava 2.x ([rxFlowable], [rxSingle], etc), and
49 Project Reactor ([flux], [mono], etc).
50* [ui](ui/README.md) — modules that provide coroutine dispatchers for various single-threaded UI libraries:
51 * Android, JavaFX, and Swing.
52* [integration](integration/README.md) — modules that provide integration with various asynchronous callback- and future-based libraries:
53 * JDK8 [CompletionStage.await], Guava [ListenableFuture.await], and Google Play Services [Task.await];
54 * SLF4J MDC integration via [MDCContext].
55
56## Documentation
57
58* Presentations and videos:
59 * [Introduction to Coroutines](https://www.youtube.com/watch?v=_hfBv0a09Jc) (Roman Elizarov at KotlinConf 2017, [slides](https://www.slideshare.net/elizarov/introduction-to-coroutines-kotlinconf-2017))
60 * [Deep dive into Coroutines](https://www.youtube.com/watch?v=YrrUCSi72E8) (Roman Elizarov at KotlinConf 2017, [slides](https://www.slideshare.net/elizarov/deep-dive-into-coroutines-on-jvm-kotlinconf-2017))
61 * [Kotlin Coroutines in Practice](https://www.youtube.com/watch?v=a3agLJQ6vt8) (Roman Elizarov at KotlinConf 2018, [slides](https://www.slideshare.net/elizarov/kotlin-coroutines-in-practice-kotlinconf-2018))
62* Guides and manuals:
63 * [Guide to kotlinx.coroutines by example](https://kotlinlang.org/docs/reference/coroutines/coroutines-guide.html) (**read it first**)
64 * [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md)
65 * [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md)
66 * [Debugging capabilities in kotlinx.coroutines](docs/debugging.md)
67* [Compatibility policy and experimental annotations](docs/compatibility.md)
68* [Change log for kotlinx.coroutines](CHANGES.md)
69* [Coroutines design document (KEEP)](https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md)
70* [Full kotlinx.coroutines API reference](https://kotlin.github.io/kotlinx.coroutines)
71
72## Using in your projects
73
74The libraries are published to [kotlinx](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines) bintray repository,
75linked to [JCenter](https://bintray.com/bintray/jcenter?filterByPkgName=kotlinx.coroutines) and
76pushed to [Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.jetbrains.kotlinx%20a%3Akotlinx-coroutines*).
77
78### Maven
79
80Add dependencies (you can also add other modules that you need):
81
82```xml
83<dependency>
84 <groupId>org.jetbrains.kotlinx</groupId>
85 <artifactId>kotlinx-coroutines-core</artifactId>
86 <version>1.3.1</version>
87</dependency>
88```
89
90And make sure that you use the latest Kotlin version:
91
92```xml
93<properties>
94 <kotlin.version>1.3.50</kotlin.version>
95</properties>
96```
97
98### Gradle
99
100Add dependencies (you can also add other modules that you need):
101
102```groovy
103dependencies {
104 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1'
105}
106```
107
108And make sure that you use the latest Kotlin version:
109
110```groovy
111buildscript {
112 ext.kotlin_version = '1.3.50'
113}
114```
115
116Make sure that you have either `jcenter()` or `mavenCentral()` in the list of repositories:
117
118```
119repository {
120 jcenter()
121}
122```
123
124### Gradle Kotlin DSL
125
126Add dependencies (you can also add other modules that you need):
127
128```groovy
129dependencies {
130 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1")
131}
132```
133
134And make sure that you use the latest Kotlin version:
135
136```groovy
137plugins {
138 kotlin("jvm") version "1.3.50"
139}
140```
141
142Make sure that you have either `jcenter()` or `mavenCentral()` in the list of repositories.
143
144### Multiplatform
145
146Core modules of `kotlinx.coroutines` are also available for
147[Kotlin/JS](#js) and [Kotlin/Native](#native).
148In common code that should get compiled for different platforms, add dependency to
149[`kotlinx-coroutines-core-common`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-common/1.3.1/jar)
150(follow the link to get the dependency declaration snippet).
151
152### Android
153
154Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
155module as dependency when using `kotlinx.coroutines` on Android:
156
157```groovy
158implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.1'
159```
160
161This gives you access to Android [Dispatchers.Main]
162coroutine dispatcher and also makes sure that in case of crashed coroutine with unhandled exception this
163exception is logged before crashing Android application, similarly to the way uncaught exceptions in
164threads are handled by Android runtime.
165
166#### R8 and ProGuard
167
168For R8 no actions required, it will take obfuscation rules from the jar.
169
170For Proguard you need to add options from [coroutines.pro](kotlinx-coroutines-core/jvm/resources/META-INF/proguard/coroutines.pro) to your rules manually.
171
172R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0 (3.3.0-beta also had it enabled).
173
174### JS
175
176[Kotlin/JS](https://kotlinlang.org/docs/reference/js-overview.html) version of `kotlinx.coroutines` is published as
177[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.3.1/jar)
178(follow the link to get the dependency declaration snippet).
179
180You can also use [`kotlinx-coroutines-core`](https://www.npmjs.com/package/kotlinx-coroutines-core) package via NPM.
181
182### Native
183
184[Kotlin/Native](https://kotlinlang.org/docs/reference/native-overview.html) version of `kotlinx.coroutines` is published as
185[`kotlinx-coroutines-core-native`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-native/1.3.1/jar)
186(follow the link to get the dependency declaration snippet).
187
188Only single-threaded code (JS-style) on Kotlin/Native is currently supported.
189Kotlin/Native supports only Gradle version 4.10 and you need to enable Gradle metadata in your
190`settings.gradle` file:
191
192```groovy
193enableFeaturePreview('GRADLE_METADATA')
194```
195
196Since Kotlin/Native does not generally provide binary compatibility between versions,
197you should use the same version of Kotlin/Native compiler as was used to build `kotlinx.coroutines`.
198
199## Building
200
201This library is built with Gradle. To build it, use `./gradlew build`.
202You can import this project into IDEA, but you have to delegate build actions
203to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)
204
205### Requirements
206
207* JDK >= 1.8 referred to by the `JAVA_HOME` environment variable.
208* JDK 1.6 referred to by the `JDK_16` environment variable. It is okay to have `JDK_16` pointing to `JAVA_HOME` for external contributions.
209
210## Contributions and releases
211
212All development (both new features and bug fixes) is performed in `develop` branch.
213This way `master` sources always contain sources of the most recently released version.
214Please send PRs with bug fixes to `develop` branch.
215Fixes to documentation in markdown files are an exception to this rule. They are updated directly in `master`.
216
217The `develop` branch is pushed to `master` during release.
218
219* Full release procedure checklist is [here](RELEASE.md).
220* Steps for contributing new integration modules are explained [here](integration/README.md#Contributing).
221
222<!--- MODULE kotlinx-coroutines-core -->
223<!--- INDEX kotlinx.coroutines -->
224[launch]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/launch.html
225[async]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/async.html
226[Job]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html
227[Deferred]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html
228[Dispatchers]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/index.html
229[Dispatchers.Main]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html
230[Dispatchers.Default]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html
231[delay]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/delay.html
232[yield]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/yield.html
233[coroutineScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html
234[supervisorScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/supervisor-scope.html
235[withContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html
236[withTimeout]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html
237[MainScope()]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html
238[SupervisorJob()]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html
239[CoroutineExceptionHandler]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html
240[Dispatchers.IO]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html
241[Executor.asCoroutineDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/java.util.concurrent.-executor/as-coroutine-dispatcher.html
242[Promise.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/kotlin.js.-promise/await.html
243[promise]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/promise.html
244[Window.asCoroutineDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/org.w3c.dom.-window/as-coroutine-dispatcher.html
245<!--- INDEX kotlinx.coroutines.flow -->
246[Flow]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html
247[_flow]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html
248[filter]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter.html
249[map]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html
250<!--- INDEX kotlinx.coroutines.channels -->
251[Channel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
252<!--- INDEX kotlinx.coroutines.selects -->
253[select]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html
254<!--- INDEX kotlinx.coroutines.sync -->
255[Mutex]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html
256[Semaphore]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html
257<!--- MODULE kotlinx-coroutines-test -->
258<!--- INDEX kotlinx.coroutines.test -->
259[Dispatchers.setMain]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/kotlinx.coroutines.-dispatchers/set-main.html
260[TestCoroutineScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/index.html
261<!--- MODULE kotlinx-coroutines-debug -->
262<!--- INDEX kotlinx.coroutines.debug -->
263[DebugProbes]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/index.html
264<!--- INDEX kotlinx.coroutines.debug.junit4 -->
265[CoroutinesTimeout]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/index.html
266<!--- MODULE kotlinx-coroutines-slf4j -->
267<!--- INDEX kotlinx.coroutines.slf4j -->
268[MDCContext]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html
269<!--- MODULE kotlinx-coroutines-jdk8 -->
270<!--- INDEX kotlinx.coroutines.future -->
271[CompletionStage.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/java.util.concurrent.-completion-stage/await.html
272<!--- MODULE kotlinx-coroutines-guava -->
273<!--- INDEX kotlinx.coroutines.guava -->
274[ListenableFuture.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-guava/kotlinx.coroutines.guava/com.google.common.util.concurrent.-listenable-future/await.html
275<!--- MODULE kotlinx-coroutines-play-services -->
276<!--- INDEX kotlinx.coroutines.tasks -->
277[Task.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/com.google.android.gms.tasks.-task/await.html
278<!--- MODULE kotlinx-coroutines-reactive -->
279<!--- INDEX kotlinx.coroutines.reactive -->
280[Publisher.collect]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/org.reactivestreams.-publisher/collect.html
281[Publisher.awaitSingle]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/org.reactivestreams.-publisher/await-single.html
282[publish]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html
283<!--- MODULE kotlinx-coroutines-rx2 -->
284<!--- INDEX kotlinx.coroutines.rx2 -->
285[rxFlowable]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html
286[rxSingle]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html
287<!--- MODULE kotlinx-coroutines-reactor -->
288<!--- INDEX kotlinx.coroutines.reactor -->
289[flux]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/flux.html
290[mono]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/mono.html
291<!--- END -->
292