Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
.github/ISSUE_TEMPLATE/ | 03-May-2024 | - | 116 | 83 | ||
.idea/ | 03-May-2024 | - | 74 | 73 | ||
android-annotation-stubs/ | 03-May-2024 | - | 96 | 47 | ||
benchmarks/ | 03-May-2024 | - | 4,532 | 3,331 | ||
buildSrc/ | 03-May-2024 | - | 1,013 | 678 | ||
docs/ | 03-May-2024 | - | 8,108 | 6,124 | ||
dokka-templates/ | 03-May-2024 | - | 4 | 4 | ||
gradle/ | 03-May-2024 | - | 603 | 486 | ||
integration/ | 03-May-2024 | - | 2,659 | 1,859 | ||
integration-testing/ | 03-May-2024 | - | 1,032 | 708 | ||
js/ | 03-May-2024 | - | 303 | 250 | ||
kotlinx-coroutines-bom/ | 03-May-2024 | - | 46 | 42 | ||
kotlinx-coroutines-core/ | 03-May-2024 | - | 76,803 | 51,612 | ||
kotlinx-coroutines-debug/ | 03-May-2024 | - | 4,224 | 3,034 | ||
kotlinx-coroutines-test/ | 03-May-2024 | - | 7,622 | 5,371 | ||
license/ | 03-May-2024 | - | 9 | 7 | ||
reactive/ | 03-May-2024 | - | 17,322 | 13,214 | ||
site/ | 03-May-2024 | - | 230 | 229 | ||
ui/ | 03-May-2024 | - | 3,970 | 3,007 | ||
.gitignore | D | 03-May-2024 | 233 | 17 | 16 | |
Android.bp | D | 03-May-2024 | 7.2 KiB | 230 | 215 | |
CHANGES.md | D | 03-May-2024 | 6 KiB | 89 | 74 | |
CHANGES_UP_TO_1.7.md | D | 03-May-2024 | 110 KiB | 1,607 | 1,339 | |
CODE_OF_CONDUCT.md | D | 03-May-2024 | 269 | 5 | 2 | |
CONTRIBUTING.md | D | 03-May-2024 | 5.4 KiB | 102 | 80 | |
LICENSE | D | 03-May-2024 | 11.1 KiB | 203 | 169 | |
LICENSE.txt | D | 03-May-2024 | 11.1 KiB | 203 | 169 | |
METADATA | D | 03-May-2024 | 527 | 20 | 18 | |
MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | |||
OWNERS | D | 03-May-2024 | 36 | 3 | 2 | |
README.md | D | 03-May-2024 | 15.6 KiB | 295 | 223 | |
RELEASE.md | D | 03-May-2024 | 3.1 KiB | 82 | 60 | |
build.gradle | D | 03-May-2024 | 14 KiB | 379 | 320 | |
bump-version.sh | D | 03-May-2024 | 2.6 KiB | 97 | 78 | |
coroutines-guide.md | D | 03-May-2024 | 294 | 4 | 2 | |
gradle.properties | D | 03-May-2024 | 1.5 KiB | 62 | 54 | |
gradlew | D | 03-May-2024 | 5.1 KiB | 174 | 125 | |
gradlew.bat | D | 03-May-2024 | 2.6 KiB | 90 | 68 | |
knit.properties | D | 03-May-2024 | 610 | 17 | 14 | |
settings.gradle | D | 03-May-2024 | 1.6 KiB | 58 | 46 |
README.md
1# kotlinx.coroutines 2 3[](https://kotlinlang.org/docs/components-stability.html) 4[](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) 5[](https://www.apache.org/licenses/LICENSE-2.0) 6[](https://central.sonatype.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.7.2) 7[](http://kotlinlang.org) 8[](https://kotlinlang.slack.com/messages/coroutines/) 9 10Library support for Kotlin coroutines with [multiplatform](#multiplatform) support. 11This is a companion version for the Kotlin `1.8.20` release. 12 13```kotlin 14suspend fun main() = coroutineScope { 15 launch { 16 delay(1000) 17 println("Kotlin Coroutines World!") 18 } 19 println("Hello") 20} 21``` 22 23> Play with coroutines online [here](https://pl.kotl.in/9zva88r7S) 24 25## Modules 26 27* [core](kotlinx-coroutines-core/README.md) — common coroutines across all platforms: 28 * [launch] and [async] coroutine builders returning [Job] and [Deferred] light-weight futures with cancellation support; 29 * [Dispatchers] object with [Main][Dispatchers.Main] dispatcher for Android/Swing/JavaFx, and [Default][Dispatchers.Default] dispatcher for background coroutines; 30 * [delay] and [yield] top-level suspending functions; 31 * [Flow] — cold asynchronous stream with [flow][_flow] builder and comprehensive operator set ([filter], [map], etc); 32 * [Channel], [Mutex], and [Semaphore] communication and synchronization primitives; 33 * [coroutineScope][_coroutineScope], [supervisorScope][_supervisorScope], [withContext], and [withTimeout] scope builders; 34 * [MainScope()] for Android and UI applications; 35 * [SupervisorJob()] and [CoroutineExceptionHandler] for supervision of coroutines hierarchies; 36 * [select] expression support and more. 37* [core/jvm](kotlinx-coroutines-core/jvm/) — additional core features available on Kotlin/JVM: 38 * [Dispatchers.IO] dispatcher for blocking coroutines; 39 * [Executor.asCoroutineDispatcher][asCoroutineDispatcher] extension, custom thread pools, and more. 40 * Integrations with `CompletableFuture` and JVM-specific extensions. 41* [core/js](kotlinx-coroutines-core/js/) — additional core features available on Kotlin/JS: 42 * Integration with `Promise` via [Promise.await] and [promise] builder; 43 * Integration with `Window` via [Window.asCoroutineDispatcher], etc. 44* [test](kotlinx-coroutines-test/README.md) — test utilities for coroutines: 45 * [Dispatchers.setMain] to override [Dispatchers.Main] in tests; 46 * [TestCoroutineScope] to test suspending functions and coroutines. 47* [debug](kotlinx-coroutines-debug/README.md) — debug utilities for coroutines: 48 * [DebugProbes] API to probe, keep track of, print and dump active coroutines; 49 * [CoroutinesTimeout] test rule to automatically dump coroutines on test timeout. 50 * Automatic integration with [BlockHound](https://github.com/reactor/BlockHound). 51* [reactive](reactive/README.md) — modules that provide builders and iteration support for various reactive streams libraries: 52 * Reactive Streams ([Publisher.collect], [Publisher.awaitSingle], [kotlinx.coroutines.reactive.publish], etc), 53 * Flow (JDK 9) (the same interface as for Reactive Streams), 54 * RxJava 2.x ([rxFlowable], [rxSingle], etc), and 55 * RxJava 3.x ([rxFlowable], [rxSingle], etc), and 56 * Project Reactor ([flux], [mono], etc). 57* [ui](ui/README.md) — modules that provide coroutine dispatchers for various single-threaded UI libraries: 58 * Android, JavaFX, and Swing. 59* [integration](integration/README.md) — modules that provide integration with various asynchronous callback- and future-based libraries: 60 * Guava [ListenableFuture.await], and Google Play Services [Task.await]; 61 * SLF4J MDC integration via [MDCContext]. 62 63## Documentation 64 65* Presentations and videos: 66 * [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)) 67 * [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)) 68 * [History of Structured Concurrency in Coroutines](https://www.youtube.com/watch?v=Mj5P47F6nJg) (Roman Elizarov at Hydra 2019, [slides](https://speakerdeck.com/elizarov/structured-concurrency)) 69* Guides and manuals: 70 * [Guide to kotlinx.coroutines by example](https://kotlinlang.org/docs/coroutines-guide.html) (**read it first**) 71 * [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md) 72 * [Debugging capabilities in kotlinx.coroutines](docs/topics/debugging.md) 73* [Compatibility policy and experimental annotations](docs/topics/compatibility.md) 74* [Change log for kotlinx.coroutines](CHANGES.md) 75* [Coroutines design document (KEEP)](https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md) 76* [Full kotlinx.coroutines API reference](https://kotlinlang.org/api/kotlinx.coroutines/) 77 78## Using in your projects 79 80### Maven 81 82Add dependencies (you can also add other modules that you need): 83 84```xml 85<dependency> 86 <groupId>org.jetbrains.kotlinx</groupId> 87 <artifactId>kotlinx-coroutines-core</artifactId> 88 <version>1.7.2</version> 89</dependency> 90``` 91 92And make sure that you use the latest Kotlin version: 93 94```xml 95<properties> 96 <kotlin.version>1.8.20</kotlin.version> 97</properties> 98``` 99 100### Gradle 101 102Add dependencies (you can also add other modules that you need): 103 104```kotlin 105dependencies { 106 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2") 107} 108``` 109 110And make sure that you use the latest Kotlin version: 111 112```kotlin 113plugins { 114 // For build.gradle.kts (Kotlin DSL) 115 kotlin("jvm") version "1.8.20" 116 117 // For build.gradle (Groovy DSL) 118 id "org.jetbrains.kotlin.jvm" version "1.8.20" 119} 120``` 121 122Make sure that you have `mavenCentral()` in the list of repositories: 123 124```kotlin 125repositories { 126 mavenCentral() 127} 128``` 129 130### Android 131 132Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android) 133module as a dependency when using `kotlinx.coroutines` on Android: 134 135```kotlin 136implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.2") 137``` 138 139This gives you access to the Android [Dispatchers.Main] 140coroutine dispatcher and also makes sure that in case of a crashed coroutine with an unhandled exception that 141this exception is logged before crashing the Android application, similarly to the way uncaught exceptions in 142threads are handled by the Android runtime. 143 144#### R8 and ProGuard 145 146R8 and ProGuard rules are bundled into the [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android) module. 147For more details see ["Optimization" section for Android](ui/kotlinx-coroutines-android/README.md#optimization). 148 149#### Avoiding including the debug infrastructure in the resulting APK 150 151The `kotlinx-coroutines-core` artifact contains a resource file that is not required for the coroutines to operate 152normally and is only used by the debugger. To exclude it at no loss of functionality, add the following snippet to the 153`android` block in your Gradle file for the application subproject: 154 155```kotlin 156packagingOptions { 157 resources.excludes += "DebugProbesKt.bin" 158} 159``` 160 161### Multiplatform 162 163Core modules of `kotlinx.coroutines` are also available for 164[Kotlin/JS](https://kotlinlang.org/docs/reference/js-overview.html) and [Kotlin/Native](https://kotlinlang.org/docs/reference/native-overview.html). 165 166In common code that should get compiled for different platforms, you can add a dependency to `kotlinx-coroutines-core` right to the `commonMain` source set: 167 168```kotlin 169commonMain { 170 dependencies { 171 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2") 172 } 173} 174``` 175 176No more additional dependencies are needed, platform-specific artifacts will be resolved automatically via Gradle metadata available since Gradle 5.3. 177 178Platform-specific dependencies are recommended to be used only for non-multiplatform projects that are compiled only for target platform. 179 180#### JS 181 182Kotlin/JS version of `kotlinx.coroutines` is published as 183[`kotlinx-coroutines-core-js`](https://central.sonatype.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.7.2) 184(follow the link to get the dependency declaration snippet) and as [`kotlinx-coroutines-core`](https://www.npmjs.com/package/kotlinx-coroutines-core) NPM package. 185 186#### Native 187 188Kotlin/Native version of `kotlinx.coroutines` is published as 189[`kotlinx-coroutines-core-$platform`](https://central.sonatype.com/search?q=kotlinx-coroutines-core&namespace=org.jetbrains.kotlinx) where `$platform` is 190the target Kotlin/Native platform. 191Targets are provided in accordance with [official K/N target support](https://kotlinlang.org/docs/native-target-support.html). 192## Building and Contributing 193 194See [Contributing Guidelines](CONTRIBUTING.md). 195 196<!--- MODULE kotlinx-coroutines-core --> 197<!--- INDEX kotlinx.coroutines --> 198 199[launch]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/launch.html 200[async]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/async.html 201[Job]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html 202[Deferred]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html 203[Dispatchers]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/index.html 204[Dispatchers.Main]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html 205[Dispatchers.Default]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html 206[delay]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/delay.html 207[yield]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/yield.html 208[_coroutineScope]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html 209[_supervisorScope]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/supervisor-scope.html 210[withContext]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html 211[withTimeout]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html 212[MainScope()]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html 213[SupervisorJob()]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html 214[CoroutineExceptionHandler]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html 215[Dispatchers.IO]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-i-o.html 216[asCoroutineDispatcher]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html 217[Promise.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/await.html 218[promise]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/promise.html 219[Window.asCoroutineDispatcher]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html 220 221<!--- INDEX kotlinx.coroutines.flow --> 222 223[Flow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html 224[_flow]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html 225[filter]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter.html 226[map]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html 227 228<!--- INDEX kotlinx.coroutines.channels --> 229 230[Channel]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html 231 232<!--- INDEX kotlinx.coroutines.selects --> 233 234[select]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html 235 236<!--- INDEX kotlinx.coroutines.sync --> 237 238[Mutex]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html 239[Semaphore]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html 240 241<!--- MODULE kotlinx-coroutines-test --> 242<!--- INDEX kotlinx.coroutines.test --> 243 244[Dispatchers.setMain]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/set-main.html 245[TestCoroutineScope]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/index.html 246 247<!--- MODULE kotlinx-coroutines-debug --> 248<!--- INDEX kotlinx.coroutines.debug --> 249 250[DebugProbes]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/index.html 251 252<!--- INDEX kotlinx.coroutines.debug.junit4 --> 253 254[CoroutinesTimeout]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/index.html 255 256<!--- MODULE kotlinx-coroutines-slf4j --> 257<!--- INDEX kotlinx.coroutines.slf4j --> 258 259[MDCContext]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html 260 261<!--- MODULE kotlinx-coroutines-jdk8 --> 262<!--- INDEX kotlinx.coroutines.future --> 263<!--- MODULE kotlinx-coroutines-guava --> 264<!--- INDEX kotlinx.coroutines.guava --> 265 266[ListenableFuture.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-guava/kotlinx.coroutines.guava/await.html 267 268<!--- MODULE kotlinx-coroutines-play-services --> 269<!--- INDEX kotlinx.coroutines.tasks --> 270 271[Task.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/await.html 272 273<!--- MODULE kotlinx-coroutines-reactive --> 274<!--- INDEX kotlinx.coroutines.reactive --> 275 276[Publisher.collect]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/collect.html 277[Publisher.awaitSingle]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-single.html 278[kotlinx.coroutines.reactive.publish]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html 279 280<!--- MODULE kotlinx-coroutines-rx2 --> 281<!--- INDEX kotlinx.coroutines.rx2 --> 282 283[rxFlowable]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html 284[rxSingle]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html 285 286<!--- MODULE kotlinx-coroutines-rx2 --> 287<!--- INDEX kotlinx.coroutines.rx2 --> 288<!--- MODULE kotlinx-coroutines-reactor --> 289<!--- INDEX kotlinx.coroutines.reactor --> 290 291[flux]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/flux.html 292[mono]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/mono.html 293 294<!--- END --> 295