Skip to content

Commit 65e1b84

Browse files
authored
Merge pull request #2675 from Kotlin/version-1.5.0-rc
Version 1.5.0-RC
2 parents f19ae19 + 497312e commit 65e1b84

File tree

305 files changed

+6687
-5489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+6687
-5489
lines changed

CHANGES.md

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# Change log for kotlinx.coroutines
22

3+
## Version 1.5.0-RC
4+
5+
### Channels API
6+
7+
* Major channels API rework (#330, #974). Existing `offer`, `poll`, and `sendBlocking` methods are deprecated, internal `receiveCatching` and `onReceiveCatching` removed, `receiveOrNull` and `onReceiveOrNull` are completely deprecated. Previously deprecated `SendChannel.isFull` declaration is removed. Channel operators deprecated with `ERROR` are now `HIDDEN`.
8+
* New methods `receiveCatching`, `onReceiveCatching` `trySend`, `tryReceive`, and `trySendBlocking` along with the new result type `ChannelResult` are introduced. They provide better type safety, are less error-prone, and have a consistent future-proof naming scheme. The full rationale behind this change can be found [here](https://github.com/Kotlin/kotlinx.coroutines/issues/974#issuecomment-806569582).
9+
* `BroadcastChannel` and `ConflatedBroadcastChannel` are marked as `ObsoleteCoroutinesApi` in the favor or `SharedFlow` and `StateFlow`. The migration scheme can be found in their documentation. These classes will be deprecated in the next major release.
10+
* `callbackFlow` and `channelFlow` are promoted to stable API.
11+
12+
### Reactive integrations
13+
14+
* All existing API in modules `kotlinx-coroutines-rx2`, `kotlinx-coroutines-rx3`, `kotlinx-coroutines-reactive`, `kotlinx-coroutines-reactor`, and `kotlinx-coroutines-jdk9` were revisited and promoted to stable (#2545).
15+
* `publish` is no longer allowed to emit `null` values (#2646).
16+
* Misleading `awaitSingleOr*` functions on `Publisher` type are deprecated (#2591).
17+
* `MaybeSource.await` is deprecated in the favor of `awaitSingle`, additional lint functions for `Mono` are added in order to prevent ambiguous `Publisher` usages (#2628, #1587).
18+
* `ContextView` support in `kotlinx-coroutines-reactor` (#2575).
19+
* All reactive builders no longer ignore inner cancellation exceptions preventing their completion (#2262, #2646).
20+
* `MaybeSource.collect` and `Maybe.collect` properly finish when they are completed without a value (#2617).
21+
* All exceptions are now consistently handled according to reactive specification, whether they are considered 'fatal' or not by reactive frameworks (#2646).
22+
23+
### Other improvements
24+
25+
* `Flow.last` and `Flow.lastOrNull` operators (#2246).
26+
* `Flow.runningFold` operator (#2641).
27+
* `CoroutinesTimeout` rule for JUnit5 (#2197).
28+
* Internals of `Job` and `AbstractCoroutine` was reworked, resulting in smaller code size, less memory footprint, and better performance (#2513, #2512).
29+
* `CancellationException` from Kotlin standard library is used for cancellation on Koltin/JS and Kotlin/Native (#2638).
30+
* Introduced new `DelicateCoroutineApi` annotation that warns users about potential target API pitfalls and suggests studying API's documentation first. The only delicate API right now is `GlobalScope` (#2637).
31+
* Fixed bug introduced in `1.4.3` when `kotlinx-coroutines-core.jar` triggered IDEA debugger failure (#2619).
32+
* Fixed memory leak of `ChildHandlerNode` with reusable continuations (#2564).
33+
* Various documentation improvements (#2555, #2589, #2592, #2583, #2437, #2616, #2633, #2560).
34+
335
## Version 1.4.3
436

537
### General changes

CONTRIBUTING.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ so do familiarize yourself with the following guidelines.
5252
* Follow the style of writing tests that is used in this project:
5353
name test functions as `testXxx`. Don't use backticks in test names.
5454
* If you introduce any new public APIs:
55+
* Comment on the existing issue if you want to work on it or create one beforehand.
56+
Ensure that the issue not only describes a problem, but also describes a solution that had received a positive feedback. Propose a solution if there isn't any.
57+
PRs with new API, but without a corresponding issue with a positive feedback about the proposed implementation are unlikely to
58+
be approved or reviewed.
5559
* All new APIs must come with documentation and tests.
5660
* All new APIs are initially released with `@ExperimentalCoroutineApi` annotation and are graduated later.
5761
* [Update the public API dumps](#updating-the-public-api-dump) and commit the resulting changes as well.
5862
It will not pass the tests otherwise.
5963
* If you plan large API additions, then please start by submitting an issue with the proposed API design
6064
to gather community feedback.
6165
* [Contact the maintainers](#contacting-maintainers) to coordinate any big piece of work in advance.
62-
* Comment on the existing issue if you want to work on it. Ensure that the issue not only describes a problem,
63-
but also describes a solution that had received a positive feedback. Propose a solution if there isn't any.
6466
* Steps for contributing new integration modules are explained [here](integration/README.md#Contributing).
6567

6668
## Building

README.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
[![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
44
[![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://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.4.3)](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.4.3/pom)
6-
[![Kotlin](https://img.shields.io/badge/kotlin-1.4.30-blue.svg?logo=kotlin)](http://kotlinlang.org)
5+
[![Download](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.5.0-RC)](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.5.0-RC/pom)
6+
[![Kotlin](https://img.shields.io/badge/kotlin-1.5.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
77
[![Slack channel](https://img.shields.io/badge/chat-slack-green.svg?logo=slack)](https://kotlinlang.slack.com/messages/coroutines/)
88

99
Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
10-
This is a companion version for the Kotlin `1.4.30` release.
10+
This is a companion version for the Kotlin `1.5.0` release.
1111

1212
```kotlin
1313
suspend fun main() = coroutineScope {
@@ -75,10 +75,6 @@ suspend fun main() = coroutineScope {
7575

7676
## Using in your projects
7777

78-
The libraries are published to [kotlinx](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines) Bintray repository,
79-
linked to [JCenter](https://bintray.com/bintray/jcenter?filterByPkgName=kotlinx.coroutines) and
80-
pushed to [Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.jetbrains.kotlinx%20a%3Akotlinx-coroutines*).
81-
8278
### Maven
8379

8480
Add dependencies (you can also add other modules that you need):
@@ -87,15 +83,15 @@ Add dependencies (you can also add other modules that you need):
8783
<dependency>
8884
<groupId>org.jetbrains.kotlinx</groupId>
8985
<artifactId>kotlinx-coroutines-core</artifactId>
90-
<version>1.4.3</version>
86+
<version>1.5.0-RC</version>
9187
</dependency>
9288
```
9389

9490
And make sure that you use the latest Kotlin version:
9591

9692
```xml
9793
<properties>
98-
<kotlin.version>1.4.30</kotlin.version>
94+
<kotlin.version>1.5.0</kotlin.version>
9995
</properties>
10096
```
10197

@@ -105,15 +101,15 @@ Add dependencies (you can also add other modules that you need):
105101

106102
```groovy
107103
dependencies {
108-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
104+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC'
109105
}
110106
```
111107

112108
And make sure that you use the latest Kotlin version:
113109

114110
```groovy
115111
buildscript {
116-
ext.kotlin_version = '1.4.30'
112+
ext.kotlin_version = '1.5.0'
117113
}
118114
```
119115

@@ -131,15 +127,15 @@ Add dependencies (you can also add other modules that you need):
131127

132128
```groovy
133129
dependencies {
134-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
130+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC")
135131
}
136132
```
137133

138134
And make sure that you use the latest Kotlin version:
139135

140136
```groovy
141137
plugins {
142-
kotlin("jvm") version "1.4.30"
138+
kotlin("jvm") version "1.5.0"
143139
}
144140
```
145141

@@ -151,7 +147,7 @@ Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
151147
module as a dependency when using `kotlinx.coroutines` on Android:
152148

153149
```groovy
154-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
150+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0-RC'
155151
```
156152

157153
This gives you access to the Android [Dispatchers.Main]
@@ -184,7 +180,7 @@ In common code that should get compiled for different platforms, you can add a d
184180
```groovy
185181
commonMain {
186182
dependencies {
187-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
183+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC")
188184
}
189185
}
190186
```
@@ -196,7 +192,7 @@ Platform-specific dependencies are recommended to be used only for non-multiplat
196192
#### JS
197193

198194
Kotlin/JS version of `kotlinx.coroutines` is published as
199-
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.4.3/jar)
195+
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.5.0-RC/jar)
200196
(follow the link to get the dependency declaration snippet) and as [`kotlinx-coroutines-core`](https://www.npmjs.com/package/kotlinx-coroutines-core) NPM package.
201197

202198
#### Native

build.gradle

+6-16
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,11 @@ buildscript {
5353
}
5454

5555
repositories {
56-
maven {url "https://kotlin.bintray.com/kotlinx"}
57-
// Future replacement for kotlin-dev, with cache redirector
58-
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
59-
maven {
60-
url "https://kotlin.bintray.com/kotlin-dev"
61-
credentials {
62-
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
63-
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
64-
}
65-
}
56+
// Leftover until we migrated to Dokka 1.4.30
57+
maven { url "https://kotlin.bintray.com/kotlin-dev" }
6658
maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
6759
maven { url "https://plugins.gradle.org/m2/" }
60+
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
6861
}
6962

7063
dependencies {
@@ -150,9 +143,6 @@ allprojects {
150143
*/
151144
google()
152145
mavenCentral()
153-
// Future replacement for kotlin-dev, with cache redirector
154-
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
155-
maven { url "https://kotlin.bintray.com/kotlinx" }
156146
}
157147
}
158148

@@ -163,9 +153,9 @@ configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != core
163153
apply plugin: "kotlin-${platform}-conventions"
164154
dependencies {
165155
// See comment below for rationale, it will be replaced with "project" dependency
166-
compile project(":$coreModule")
156+
api project(":$coreModule")
167157
// the only way IDEA can resolve test classes
168-
testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
158+
testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
169159
}
170160
}
171161

@@ -243,7 +233,7 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
243233
if (it.name != 'kotlinx-coroutines-bom') {
244234
apply from: rootProject.file('gradle/dokka.gradle')
245235
}
246-
apply from: rootProject.file('gradle/publish-bintray.gradle')
236+
apply from: rootProject.file('gradle/publish.gradle')
247237
}
248238

249239
configure(subprojects.findAll { !unpublished.contains(it.name) }) {

buildSrc/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ repositories {
1717
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev")
1818
} else {
1919
maven("https://plugins.gradle.org/m2")
20+
// Leftover until we migrated to Dokka 1.4.30
2021
maven("https://dl.bintray.com/kotlin/kotlin-dev")
2122
}
23+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
2224

2325
if (buildSnapshotTrain) {
2426
mavenLocal()

buildSrc/src/main/kotlin/Publishing.kt

-14
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ fun configureMavenPublication(rh: RepositoryHandler, project: Project) {
6262
}
6363
}
6464

65-
fun configureBintrayPublication(rh: RepositoryHandler, project: Project) {
66-
rh.maven {
67-
val user = "kotlin"
68-
val repo = "kotlinx"
69-
val name = "kotlinx.coroutines"
70-
url = URI("https://api.bintray.com/maven/$user/$repo/$name/;publish=0;override=0")
71-
72-
credentials {
73-
username = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER")
74-
password = project.findProperty("bintrayApiKey") as? String ?: System.getenv("BINTRAY_API_KEY")
75-
}
76-
}
77-
}
78-
7965
fun signPublicationIfKeyPresent(project: Project, publication: MavenPublication) {
8066
val keyId = project.getSensitiveProperty("libs.sign.key.id")
8167
val signingKey = project.getSensitiveProperty("libs.sign.key.private")

buildSrc/src/main/kotlin/kotlin-jvm-conventions.gradle.kts

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ if (rootProject.extra.get("jvm_ir_enabled") as Boolean) {
2222
}
2323

2424
dependencies {
25-
testCompile(kotlin("test"))
25+
testImplementation(kotlin("test"))
2626
// Workaround to make addSuppressed work in tests
27-
testCompile(kotlin("reflect"))
28-
testCompile(kotlin("stdlib-jdk7"))
29-
testCompile(kotlin("test-junit"))
30-
testCompile("junit:junit:${version("junit")}")
27+
testImplementation(kotlin("reflect"))
28+
testImplementation(kotlin("stdlib-jdk7"))
29+
testImplementation(kotlin("test-junit"))
30+
testImplementation("junit:junit:${version("junit")}")
3131
}
3232

3333
tasks.compileKotlin {

docs/images/after.png

-134 KB
Loading

docs/images/before.png

-61.8 KB
Loading

docs/images/new-mvn-project-jvm.png

-370 KB
Binary file not shown.

docs/topics/composing-suspending-functions.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ suspend fun doSomethingUsefulTwo(): Int {
2424

2525
What do we do if we need them to be invoked _sequentially_ &mdash; first `doSomethingUsefulOne` _and then_
2626
`doSomethingUsefulTwo`, and compute the sum of their results?
27-
In practice we do this if we use the result of the first function to make a decision on whether we need
27+
In practice, we do this if we use the result of the first function to make a decision on whether we need
2828
to invoke the second one or to decide on how to invoke it.
2929

3030
We use a normal sequential invocation, because the code in the coroutine, just like in the regular
@@ -190,18 +190,26 @@ standard `lazy` function in cases when computation of the value involves suspend
190190
## Async-style functions
191191

192192
We can define async-style functions that invoke `doSomethingUsefulOne` and `doSomethingUsefulTwo`
193-
_asynchronously_ using the [async] coroutine builder with an explicit [GlobalScope] reference.
193+
_asynchronously_ using the [async] coroutine builder using a [GlobalScope] reference to
194+
opt-out of the structured concurrency.
194195
We name such functions with the
195196
"...Async" suffix to highlight the fact that they only start asynchronous computation and one needs
196197
to use the resulting deferred value to get the result.
197198

199+
> [GlobalScope] is a delicate API that can backfire in non-trivial ways, one of which will be explained
200+
> below, so you must explicitly opt-in into using `GlobalScope` with `@OptIn(DelicateCoroutinesApi::class)`.
201+
>
202+
{type="note"}
203+
198204
```kotlin
199205
// The result type of somethingUsefulOneAsync is Deferred<Int>
206+
@OptIn(DelicateCoroutinesApi::class)
200207
fun somethingUsefulOneAsync() = GlobalScope.async {
201208
doSomethingUsefulOne()
202209
}
203210

204211
// The result type of somethingUsefulTwoAsync is Deferred<Int>
212+
@OptIn(DelicateCoroutinesApi::class)
205213
fun somethingUsefulTwoAsync() = GlobalScope.async {
206214
doSomethingUsefulTwo()
207215
}
@@ -236,10 +244,12 @@ fun main() {
236244
}
237245
//sampleEnd
238246

247+
@OptIn(DelicateCoroutinesApi::class)
239248
fun somethingUsefulOneAsync() = GlobalScope.async {
240249
doSomethingUsefulOne()
241250
}
242251

252+
@OptIn(DelicateCoroutinesApi::class)
243253
fun somethingUsefulTwoAsync() = GlobalScope.async {
244254
doSomethingUsefulTwo()
245255
}
@@ -272,9 +282,9 @@ Completed in 1085 ms
272282
{type="note"}
273283

274284
Consider what happens if between the `val one = somethingUsefulOneAsync()` line and `one.await()` expression there is some logic
275-
error in the code and the program throws an exception and the operation that was being performed by the program aborts.
285+
error in the code, and the program throws an exception, and the operation that was being performed by the program aborts.
276286
Normally, a global error-handler could catch this exception, log and report the error for developers, but the program
277-
could otherwise continue doing other operations. But here we have `somethingUsefulOneAsync` still running in the background,
287+
could otherwise continue doing other operations. However, here we have `somethingUsefulOneAsync` still running in the background,
278288
even though the operation that initiated it was aborted. This problem does not happen with structured
279289
concurrency, as shown in the section below.
280290

@@ -293,7 +303,7 @@ suspend fun concurrentSum(): Int = coroutineScope {
293303
}
294304
```
295305

296-
This way, if something goes wrong inside the code of the `concurrentSum` function and it throws an exception,
306+
This way, if something goes wrong inside the code of the `concurrentSum` function, and it throws an exception,
297307
all the coroutines that were launched in its scope will be cancelled.
298308

299309
<!--- CLEAR -->
@@ -403,4 +413,4 @@ Computation failed with ArithmeticException
403413
[CoroutineScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html
404414
[_coroutineScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html
405415

406-
<!--- END -->
416+
<!--- END -->

0 commit comments

Comments
 (0)