Skip to content

Commit 1b34e1c

Browse files
authored
Merge pull request #2297 from Kotlin/version-1.4.0-M1
Version 1.4.0-M1
2 parents 401c05c + f3a9b60 commit 1b34e1c

File tree

244 files changed

+9012
-1864
lines changed

Some content is hidden

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

244 files changed

+9012
-1864
lines changed

CHANGES.md

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

3+
## Version 1.4.0-M1
4+
5+
### Breaking changes
6+
7+
* The concept of atomic cancellation in channels is removed. All operations in channels
8+
and corresponding `Flow` operators are cancellable in non-atomic way (#1813).
9+
* If `CoroutineDispatcher` throws `RejectedExecutionException`, cancel current `Job` and schedule its execution to `Dispatchers.IO` (#2003).
10+
* `CancellableContinuation.invokeOnCancellation` is invoked if the continuation was cancelled while its resume has been dispatched (#1915).
11+
* `Flow.singleOrNull` operator is aligned with standard library and does not longer throw `IllegalStateException` on multiple values (#2289).
12+
13+
### New experimental features
14+
15+
* `SharedFlow` primitive for managing hot sources of events with support of various subscription mechanisms, replay logs and buffering (#2034).
16+
* `Flow.shareIn` and `Flow.stateIn` operators to transform cold instances of flow to hot `SharedFlow` and `StateFlow` respectively (#2047).
17+
18+
### Other
19+
20+
* Support leak-free closeable resources transfer via `onUndeliveredElement` in channels (#1936).
21+
* Changed ABI in reactive integrations for Java interoperability (#2182).
22+
* Fixed ProGuard rules for `kotlinx-coroutines-core` (#2046, #2266).
23+
* Lint settings were added to `Flow` to avoid accidental capturing of outer `CoroutineScope` for cancellation check (#2038).
24+
25+
### External contributions
26+
27+
* Allow nullable types in `Flow.firstOrNull` and `Flow.singleOrNull` by @ansman (#2229).
28+
* Add `Publisher.awaitSingleOrDefault|Null|Else` extensions by @sdeleuze (#1993).
29+
* `awaitCancellation` top-level function by @LouisCAD (#2213).
30+
* Significant part of our Gradle build scripts were migrated to `.kts` by @turansky.
31+
32+
Thank you for your contributions and participation in the Kotlin community!
33+
334
## Version 1.3.9
435

536
* Support of `CoroutineContext` in `Flow.asPublisher` and similar reactive builders (#2155).

README.md

+23-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
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://api.bintray.com/packages/kotlin/kotlinx/kotlinx.coroutines/images/download.svg?version=1.3.9) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.3.9)
5+
[![Download](https://api.bintray.com/packages/kotlin/kotlinx/kotlinx.coroutines/images/download.svg?version=1.4.0-M1) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.4.0-M1)
6+
[![Kotlin](https://img.shields.io/badge/kotlin-1.4.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
7+
[![Slack channel](https://img.shields.io/badge/chat-slack-green.svg?logo=slack)](https://kotlinlang.slack.com/messages/coroutines/)
68

79
Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
810
This is a companion version for Kotlin `1.4.0` release.
@@ -44,7 +46,7 @@ suspend fun main() = coroutineScope {
4446
* [DebugProbes] API to probe, keep track of, print and dump active coroutines;
4547
* [CoroutinesTimeout] test rule to automatically dump coroutines on test timeout.
4648
* [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),
49+
* Reactive Streams ([Publisher.collect], [Publisher.awaitSingle], [kotlinx.coroutines.reactive.publish], etc),
4850
* Flow (JDK 9) (the same interface as for Reactive Streams),
4951
* RxJava 2.x ([rxFlowable], [rxSingle], etc), and
5052
* RxJava 3.x ([rxFlowable], [rxSingle], etc), and
@@ -84,7 +86,7 @@ Add dependencies (you can also add other modules that you need):
8486
<dependency>
8587
<groupId>org.jetbrains.kotlinx</groupId>
8688
<artifactId>kotlinx-coroutines-core</artifactId>
87-
<version>1.3.9</version>
89+
<version>1.4.0-M1</version>
8890
</dependency>
8991
```
9092

@@ -102,7 +104,7 @@ Add dependencies (you can also add other modules that you need):
102104

103105
```groovy
104106
dependencies {
105-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
107+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1'
106108
}
107109
```
108110

@@ -128,7 +130,7 @@ Add dependencies (you can also add other modules that you need):
128130

129131
```groovy
130132
dependencies {
131-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
133+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1")
132134
}
133135
```
134136

@@ -150,7 +152,7 @@ In common code that should get compiled for different platforms, you can add dep
150152
```groovy
151153
commonMain {
152154
dependencies {
153-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
155+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1")
154156
}
155157
}
156158
```
@@ -161,7 +163,7 @@ Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
161163
module as dependency when using `kotlinx.coroutines` on Android:
162164

163165
```groovy
164-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
166+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.0-M1'
165167
```
166168

167169
This gives you access to Android [Dispatchers.Main]
@@ -174,18 +176,29 @@ threads are handled by Android runtime.
174176
R8 and ProGuard rules are bundled into the [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android) module.
175177
For more details see ["Optimization" section for Android](ui/kotlinx-coroutines-android/README.md#optimization).
176178

179+
#### Avoiding including the debug infrastructure in the resulting APK
180+
181+
The `kotlinx-coroutines-core` artifact contains a resource file that is not required for the coroutines to operate
182+
normally and is only used by the debugger. To exclude it at no loss of functionality, add the following snippet to the
183+
`android` block in your gradle file for the application subproject:
184+
```groovy
185+
packagingOptions {
186+
exclude "DebugProbesKt.bin"
187+
}
188+
```
189+
177190
### JS
178191

179192
[Kotlin/JS](https://kotlinlang.org/docs/reference/js-overview.html) version of `kotlinx.coroutines` is published as
180-
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.3.9/jar)
193+
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.4.0-M1/jar)
181194
(follow the link to get the dependency declaration snippet).
182195

183196
You can also use [`kotlinx-coroutines-core`](https://www.npmjs.com/package/kotlinx-coroutines-core) package via NPM.
184197

185198
### Native
186199

187200
[Kotlin/Native](https://kotlinlang.org/docs/reference/native-overview.html) version of `kotlinx.coroutines` is published as
188-
[`kotlinx-coroutines-core-native`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-native/1.3.9/jar)
201+
[`kotlinx-coroutines-core-native`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-native/1.4.0-M1/jar)
189202
(follow the link to get the dependency declaration snippet).
190203

191204
Only single-threaded code (JS-style) on Kotlin/Native is currently supported.
@@ -263,7 +276,7 @@ See [Contributing Guidelines](CONTRIBUTING.md).
263276
<!--- INDEX kotlinx.coroutines.reactive -->
264277
[Publisher.collect]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/org.reactivestreams.-publisher/collect.html
265278
[Publisher.awaitSingle]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/org.reactivestreams.-publisher/await-single.html
266-
[publish]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html
279+
[kotlinx.coroutines.reactive.publish]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html
267280
<!--- MODULE kotlinx-coroutines-rx2 -->
268281
<!--- INDEX kotlinx.coroutines.rx2 -->
269282
[rxFlowable]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html

RELEASE.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,14 @@ To release new `<version>` of `kotlinx-coroutines`:
6464

6565
5. Announce new release in [Slack](https://kotlinlang.slack.com)
6666

67-
6. Create a ticket to update coroutines version on [try.kotlinlang.org](try.kotlinlang.org).
68-
* Use [KT-30870](https://youtrack.jetbrains.com/issue/KT-30870) as a template
69-
* This step should be skipped for eap versions that are not merged to `master`
70-
71-
7. Switch into `develop` branch:<br>
67+
6. Switch into `develop` branch:<br>
7268
`git checkout develop`
7369

74-
8. Fetch the latest `master`:<br>
70+
7. Fetch the latest `master`:<br>
7571
`git fetch`
7672

77-
9. Merge release from `master`:<br>
73+
8. Merge release from `master`:<br>
7874
`git merge origin/master`
7975

80-
0. Push updates to `develop`:<br>
76+
9. Push updates to `develop`:<br>
8177
`git push`

benchmarks/build.gradle.kts

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("UnstableApiUsage")
6+
57
import me.champeau.gradle.*
68
import org.jetbrains.kotlin.gradle.tasks.*
79

@@ -33,7 +35,7 @@ tasks.named<KotlinCompile>("compileJmhKotlin") {
3335
* Due to a bug in the inliner it sometimes does not remove inlined symbols (that are later renamed) from unused code paths,
3436
* and it breaks JMH that tries to post-process these symbols and fails because they are renamed.
3537
*/
36-
val removeRedundantFiles = tasks.register<Delete>("removeRedundantFiles") {
38+
val removeRedundantFiles by tasks.registering(Delete::class) {
3739
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class")
3840
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$nBlanks\$1\$\$special\$\$inlined\$map\$1\$1.class")
3941
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$score2\$1\$\$special\$\$inlined\$map\$1\$1.class")
@@ -71,10 +73,10 @@ extensions.configure<JMHPluginExtension>("jmh") {
7173
}
7274

7375
tasks.named<Jar>("jmhJar") {
74-
baseName = "benchmarks"
75-
classifier = null
76-
version = null
77-
destinationDir = file("$rootDir")
76+
archiveBaseName by "benchmarks"
77+
archiveClassifier by null
78+
archiveVersion by null
79+
destinationDirectory.file("$rootDir")
7880
}
7981

8082
dependencies {

benchmarks/src/jmh/kotlin/benchmarks/tailcall/SimpleChannel.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class NonCancellableChannel : SimpleChannel() {
7070
}
7171

7272
class CancellableChannel : SimpleChannel() {
73-
override suspend fun suspendReceive(): Int = suspendAtomicCancellableCoroutine {
73+
override suspend fun suspendReceive(): Int = suspendCancellableCoroutine {
7474
consumer = it.intercepted()
7575
COROUTINE_SUSPENDED
7676
}
7777

78-
override suspend fun suspendSend(element: Int) = suspendAtomicCancellableCoroutine<Unit> {
78+
override suspend fun suspendSend(element: Int) = suspendCancellableCoroutine<Unit> {
7979
enqueuedValue = element
8080
producer = it.intercepted()
8181
COROUTINE_SUSPENDED
@@ -84,13 +84,13 @@ class CancellableChannel : SimpleChannel() {
8484

8585
class CancellableReusableChannel : SimpleChannel() {
8686
@Suppress("INVISIBLE_MEMBER")
87-
override suspend fun suspendReceive(): Int = suspendAtomicCancellableCoroutineReusable {
87+
override suspend fun suspendReceive(): Int = suspendCancellableCoroutineReusable {
8888
consumer = it.intercepted()
8989
COROUTINE_SUSPENDED
9090
}
9191

9292
@Suppress("INVISIBLE_MEMBER")
93-
override suspend fun suspendSend(element: Int) = suspendAtomicCancellableCoroutineReusable<Unit> {
93+
override suspend fun suspendSend(element: Int) = suspendCancellableCoroutineReusable<Unit> {
9494
enqueuedValue = element
9595
producer = it.intercepted()
9696
COROUTINE_SUSPENDED

build.gradle

+23-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ buildscript {
4646
if (using_snapshot_version) {
4747
repositories {
4848
mavenLocal()
49-
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
5049
}
5150
}
5251

@@ -59,6 +58,8 @@ buildscript {
5958
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
6059
}
6160
}
61+
// Future replacement for kotlin-dev, with cache redirector
62+
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
6263
maven {
6364
url "https://kotlin.bintray.com/kotlin-dev"
6465
credentials {
@@ -82,12 +83,14 @@ buildscript {
8283
// JMH plugins
8384
classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
8485
}
86+
87+
CacheRedirector.configureBuildScript(buildscript, rootProject)
8588
}
8689

8790
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
8891

89-
// Hierarchical project structures are not fully supported in 1.3.7x MPP, enable conditionally for 1.4.x
90-
if (VersionNumber.parse(kotlin_version) > VersionNumber.parse("1.3.79")) {
92+
// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
93+
if (!Idea.active) {
9194
ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
9295
}
9396

@@ -145,14 +148,15 @@ apiValidation {
145148

146149
// Configure repositories
147150
allprojects {
148-
String projectName = it.name
149151
repositories {
150152
/*
151153
* google should be first in the repository list because some of the play services
152154
* transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
153155
*/
154156
google()
155157
jcenter()
158+
// Future replacement for kotlin-dev, with cache redirector
159+
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
156160
maven {
157161
url "https://kotlin.bintray.com/kotlin-dev"
158162
credentials {
@@ -250,7 +254,14 @@ configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }
250254
}
251255

252256
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
253-
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
257+
configure(subprojects.findAll {
258+
!sourceless.contains(it.name) &&
259+
it.name != "benchmarks" &&
260+
it.name != coreModule &&
261+
it.name != "example-frontend-js"
262+
}) {
263+
// Pure JS and pure MPP doesn't have this notion and are configured separately
264+
// TODO detect it via platformOf and migrate benchmarks to the same scheme
254265
sourceSets {
255266
main.kotlin.srcDirs = ['src']
256267
test.kotlin.srcDirs = ['test']
@@ -286,7 +297,14 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
286297
// Report Kotlin compiler version when building project
287298
println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
288299

300+
// --------------- Cache redirector ---------------
301+
302+
allprojects {
303+
CacheRedirector.configure(project)
304+
}
305+
289306
// --------------- Configure sub-projects that are published ---------------
307+
290308
def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
291309

292310
task deploy(dependsOn: publishTasks)

buildSrc/build.gradle.kts

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import java.util.*
6+
17
plugins {
28
`kotlin-dsl`
39
}
410

11+
val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
12+
513
repositories {
6-
gradlePluginPortal()
14+
if (cacheRedirectorEnabled) {
15+
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2")
16+
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-eap")
17+
maven("https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev")
18+
} else {
19+
maven("https://plugins.gradle.org/m2")
20+
maven("https://dl.bintray.com/kotlin/kotlin-eap")
21+
maven("https://dl.bintray.com/kotlin/kotlin-dev")
22+
}
723
}
824

925
kotlinDslPluginOptions {
1026
experimentalWarning.set(false)
1127
}
28+
29+
val props = Properties().apply {
30+
file("../gradle.properties").inputStream().use { load(it) }
31+
}
32+
33+
fun version(target: String): String =
34+
props.getProperty("${target}_version")
35+
36+
dependencies {
37+
implementation(kotlin("gradle-plugin", version("kotlin")))
38+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${version("dokka")}")
39+
}

buildSrc/settings.gradle.kts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
pluginManagement {
6+
repositories {
7+
val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
8+
9+
if (cacheRedirectorEnabled) {
10+
println("Redirecting repositories for buildSrc buildscript")
11+
12+
maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2")
13+
} else {
14+
maven("https://plugins.gradle.org/m2")
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)