Skip to content

Commit 247b34c

Browse files
authored
Merge pull request Kotlin#2203 from Kotlin/version-1.3.9
Version 1.3.9
2 parents 6649745 + 398fee2 commit 247b34c

File tree

31 files changed

+636
-65
lines changed

31 files changed

+636
-65
lines changed

CHANGES.md

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

3+
## Version 1.3.9
4+
5+
* Support of `CoroutineContext` in `Flow.asPublisher` and similar reactive builders (#2155).
6+
* Kotlin updated to 1.4.0.
7+
* Transition to new HMPP publication scheme for multiplatform usages:
8+
* Artifacts `kotlinx-coroutines-core-common` and `kotlinx-coroutines-core-native` are removed.
9+
* For multiplatform usages, it's enough to [depend directly](README.md#multiplatform) on `kotlinx-coroutines-core` in `commonMain` source-set.
10+
* The same artifact coordinates can be used to depend on platform-specific artifact in platform-specific source-set.
11+
312
## Version 1.3.8
413

514
### New experimental features

README.md

+19-14
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
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.8) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.3.8)
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)
66

77
Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
8-
This is a companion version for Kotlin `1.3.71` release.
8+
This is a companion version for Kotlin `1.4.0` release.
99

1010
```kotlin
1111
suspend fun main() = coroutineScope {
@@ -84,15 +84,15 @@ Add dependencies (you can also add other modules that you need):
8484
<dependency>
8585
<groupId>org.jetbrains.kotlinx</groupId>
8686
<artifactId>kotlinx-coroutines-core</artifactId>
87-
<version>1.3.8</version>
87+
<version>1.3.9</version>
8888
</dependency>
8989
```
9090

9191
And make sure that you use the latest Kotlin version:
9292

9393
```xml
9494
<properties>
95-
<kotlin.version>1.3.71</kotlin.version>
95+
<kotlin.version>1.4.0</kotlin.version>
9696
</properties>
9797
```
9898

@@ -102,15 +102,15 @@ Add dependencies (you can also add other modules that you need):
102102

103103
```groovy
104104
dependencies {
105-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
105+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
106106
}
107107
```
108108

109109
And make sure that you use the latest Kotlin version:
110110

111111
```groovy
112112
buildscript {
113-
ext.kotlin_version = '1.3.71'
113+
ext.kotlin_version = '1.4.0'
114114
}
115115
```
116116

@@ -128,15 +128,15 @@ Add dependencies (you can also add other modules that you need):
128128

129129
```groovy
130130
dependencies {
131-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8")
131+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
132132
}
133133
```
134134

135135
And make sure that you use the latest Kotlin version:
136136

137137
```groovy
138138
plugins {
139-
kotlin("jvm") version "1.3.71"
139+
kotlin("jvm") version "1.4.0"
140140
}
141141
```
142142

@@ -146,17 +146,22 @@ Make sure that you have either `jcenter()` or `mavenCentral()` in the list of re
146146

147147
Core modules of `kotlinx.coroutines` are also available for
148148
[Kotlin/JS](#js) and [Kotlin/Native](#native).
149-
In common code that should get compiled for different platforms, add dependency to
150-
[`kotlinx-coroutines-core-common`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-common/1.3.8/jar)
151-
(follow the link to get the dependency declaration snippet).
149+
In common code that should get compiled for different platforms, you can add dependency to `kotlinx-coroutines-core` right to the `commonMain` source set:
150+
```groovy
151+
commonMain {
152+
dependencies {
153+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
154+
}
155+
}
156+
```
152157

153158
### Android
154159

155160
Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
156161
module as dependency when using `kotlinx.coroutines` on Android:
157162

158163
```groovy
159-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
164+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
160165
```
161166

162167
This gives you access to Android [Dispatchers.Main]
@@ -172,15 +177,15 @@ For more details see ["Optimization" section for Android](ui/kotlinx-coroutines-
172177
### JS
173178

174179
[Kotlin/JS](https://kotlinlang.org/docs/reference/js-overview.html) version of `kotlinx.coroutines` is published as
175-
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.3.8/jar)
180+
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.3.9/jar)
176181
(follow the link to get the dependency declaration snippet).
177182

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

180185
### Native
181186

182187
[Kotlin/Native](https://kotlinlang.org/docs/reference/native-overview.html) version of `kotlinx.coroutines` is published as
183-
[`kotlinx-coroutines-core-native`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-native/1.3.8/jar)
188+
[`kotlinx-coroutines-core-native`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-native/1.3.9/jar)
184189
(follow the link to get the dependency declaration snippet).
185190

186191
Only single-threaded code (JS-style) on Kotlin/Native is currently supported.

build.gradle

+15-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ buildscript {
5252

5353
repositories {
5454
jcenter()
55-
maven { url "https://kotlin.bintray.com/kotlinx" }
55+
maven {
56+
url "https://kotlin.bintray.com/kotlinx"
57+
credentials {
58+
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
59+
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
60+
}
61+
}
5662
maven {
5763
url "https://kotlin.bintray.com/kotlin-dev"
5864
credentials {
@@ -155,7 +161,14 @@ allprojects {
155161
}
156162
}
157163
maven { url "https://kotlin.bintray.com/kotlin-eap" }
158-
maven { url "https://kotlin.bintray.com/kotlinx" }
164+
maven {
165+
url "https://kotlin.bintray.com/kotlinx"
166+
credentials {
167+
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
168+
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
169+
}
170+
}
171+
mavenLocal()
159172
}
160173
}
161174

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#
44

55
# Kotlin
6-
version=1.3.8-SNAPSHOT
6+
version=1.3.9-SNAPSHOT
77
group=org.jetbrains.kotlinx
8-
kotlin_version=1.3.71
8+
kotlin_version=1.4.0
99

1010
# Dependencies
1111
junit_version=4.12
12-
atomicfu_version=0.14.2
12+
atomicfu_version=0.14.4
1313
knit_version=0.1.3
1414
html_version=0.6.8
1515
lincheck_version=2.7.1
@@ -59,4 +59,4 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
5959
# This is commented out, and the property is set conditionally in build.gradle, because 1.3.71 doesn't work with it.
6060
# Once this property is set by default in new versions or 1.3.71 is dropped, either uncomment or remove this line.
6161
#kotlin.mpp.enableGranularSourceSetsMetadata=true
62-
kotlin.mpp.enableCompatibilityMetadataVariant=true
62+
kotlin.mpp.enableCompatibilityMetadataVariant=true

kotlinx-coroutines-core/api/kotlinx-coroutines-core.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ public abstract interface class kotlinx/coroutines/channels/ReceiveChannel {
787787
public abstract fun iterator ()Lkotlinx/coroutines/channels/ChannelIterator;
788788
public abstract fun poll ()Ljava/lang/Object;
789789
public abstract fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
790-
public abstract fun receiveOrClosed (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
790+
public abstract fun receiveOrClosed-ZYPwvRU (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
791791
public abstract fun receiveOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
792792
}
793793

kotlinx-coroutines-core/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ task jdk16Test(type: Test, dependsOn: [compileTestKotlinJvm, checkJdk16]) {
131131
exclude '**/*LCStressTest.*' // lin-check tests use LinChecker which needs JDK8
132132
exclude '**/exceptions/**' // exceptions tests check suppressed exception which needs JDK8
133133
exclude '**/ExceptionsGuideTest.*'
134+
exclude '**/RunInterruptibleStressTest.*' // fails on JDK 1.6 due to JDK bug
134135
}
135136

136137
// Run these tests only during nightly stress test

kotlinx-coroutines-core/common/src/CancellableContinuation.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ import kotlin.coroutines.intrinsics.*
2828
*
2929
* A [cancelled][isCancelled] continuation implies that it is [completed][isCompleted].
3030
*
31-
* Invocation of [resume] or [resumeWithException] in _resumed_ state produces an [IllegalStateException].
32-
* Invocation of [resume] in _cancelled_ state is ignored (it is a trivial race between resume from the continuation owner and
33-
* outer job's cancellation, and the cancellation wins).
34-
* Invocation of [resumeWithException] in _cancelled_ state triggers exception handling of the passed exception.
31+
* Invocation of [resume] or [resumeWithException] in _resumed_ state produces an [IllegalStateException],
32+
* but is ignored in _cancelled_ state.
3533
*
3634
* ```
3735
* +-----------+ resume +---------+
Binary file not shown.

kotlinx-coroutines-core/jvm/test/RunInterruptibleStressTest.kt

+13-11
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@ import org.junit.Test
99
import java.util.concurrent.atomic.*
1010
import kotlin.test.*
1111

12+
/**
13+
* Stress test for [runInterruptible].
14+
* It does not pass on JDK 1.6 on Windows: [Thread.sleep] times out without being interrupted despite the
15+
* fact that thread interruption flag is set.
16+
*/
1217
class RunInterruptibleStressTest : TestBase() {
13-
1418
@get:Rule
1519
val dispatcher = ExecutorRule(4)
16-
private val REPEAT_TIMES = 1000 * stressTestMultiplier
20+
private val repeatTimes = 1000 * stressTestMultiplier
1721

1822
@Test
19-
fun testStress() = runBlocking {
20-
val interruptLeak = AtomicBoolean(false)
23+
fun testStress() = runTest {
2124
val enterCount = AtomicInteger(0)
2225
val interruptedCount = AtomicInteger(0)
2326

24-
repeat(REPEAT_TIMES) {
27+
repeat(repeatTimes) {
2528
val job = launch(dispatcher) {
2629
try {
2730
runInterruptible {
2831
enterCount.incrementAndGet()
2932
try {
30-
Thread.sleep(Long.MAX_VALUE)
33+
Thread.sleep(10_000)
34+
error("Sleep was not interrupted, Thread.isInterrupted=${Thread.currentThread().isInterrupted}")
3135
} catch (e: InterruptedException) {
3236
interruptedCount.incrementAndGet()
3337
throw e
@@ -36,19 +40,17 @@ class RunInterruptibleStressTest : TestBase() {
3640
} catch (e: CancellationException) {
3741
// Expected
3842
} finally {
39-
interruptLeak.set(interruptLeak.get() || Thread.currentThread().isInterrupted)
43+
assertFalse(Thread.currentThread().isInterrupted, "Interrupt flag should not leak")
4044
}
4145
}
4246
// Add dispatch delay
4347
val cancelJob = launch(dispatcher) {
4448
job.cancel()
4549
}
46-
47-
job.start()
4850
joinAll(job, cancelJob)
4951
}
50-
51-
assertFalse(interruptLeak.get())
52+
println("Entered runInterruptible ${enterCount.get()} times")
53+
assertTrue(enterCount.get() > 0) // ensure timing is Ok and we don't cancel it all prematurely
5254
assertEquals(enterCount.get(), interruptedCount.get())
5355
}
5456
}

kotlinx-coroutines-debug/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ https://github.com/reactor/BlockHound/blob/1.0.2.RELEASE/docs/quick_start.md).
2323
Add `kotlinx-coroutines-debug` to your project test dependencies:
2424
```
2525
dependencies {
26-
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.3.8'
26+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.3.9'
2727
}
2828
```
2929

@@ -61,7 +61,7 @@ stacktraces will be dumped to the console.
6161
### Using as JVM agent
6262

6363
Debug module can also be used as a standalone JVM agent to enable debug probes on the application startup.
64-
You can run your application with an additional argument: `-javaagent:kotlinx-coroutines-debug-1.3.8.jar`.
64+
You can run your application with an additional argument: `-javaagent:kotlinx-coroutines-debug-1.3.9.jar`.
6565
Additionally, on Linux and Mac OS X you can use `kill -5 $pid` command in order to force your application to print all alive coroutines.
6666
When used as Java agent, `"kotlinx.coroutines.debug.enable.creation.stack.trace"` system property can be used to control
6767
[DebugProbes.enableCreationStackTraces] along with agent startup.

kotlinx-coroutines-test/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This package provides testing utilities for effectively testing coroutines.
99
Add `kotlinx-coroutines-test` to your project test dependencies:
1010
```
1111
dependencies {
12-
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8'
12+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.9'
1313
}
1414
```
1515

reactive/kotlinx-coroutines-jdk9/api/kotlinx-coroutines-jdk9.api

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public final class kotlinx/coroutines/jdk9/PublishKt {
1515
public final class kotlinx/coroutines/jdk9/ReactiveFlowKt {
1616
public static final fun asFlow (Ljava/util/concurrent/Flow$Publisher;)Lkotlinx/coroutines/flow/Flow;
1717
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;)Ljava/util/concurrent/Flow$Publisher;
18+
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Ljava/util/concurrent/Flow$Publisher;
19+
public static synthetic fun asPublisher$default (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Ljava/util/concurrent/Flow$Publisher;
1820
public static final fun collect (Ljava/util/concurrent/Flow$Publisher;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1921
}
2022

reactive/kotlinx-coroutines-jdk9/src/ReactiveFlow.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
package kotlinx.coroutines.jdk9
66

7+
import kotlinx.coroutines.*
78
import kotlinx.coroutines.flow.*
89
import kotlinx.coroutines.reactive.asFlow
910
import kotlinx.coroutines.reactive.asPublisher
1011
import kotlinx.coroutines.reactive.collect
12+
import org.reactivestreams.*
13+
import kotlin.coroutines.*
1114
import java.util.concurrent.Flow as JFlow
12-
import org.reactivestreams.FlowAdapters
1315

1416
/**
1517
* Transforms the given reactive [Publisher] into [Flow].
@@ -25,9 +27,15 @@ public fun <T : Any> JFlow.Publisher<T>.asFlow(): Flow<T> =
2527

2628
/**
2729
* Transforms the given flow to a reactive specification compliant [Publisher].
30+
*
31+
* An optional [context] can be specified to control the execution context of calls to [Subscriber] methods.
32+
* You can set a [CoroutineDispatcher] to confine them to a specific thread and/or various [ThreadContextElement] to
33+
* inject additional context into the caller thread. By default, the [Unconfined][Dispatchers.Unconfined] dispatcher
34+
* is used, so calls are performed from an arbitrary thread.
2835
*/
29-
public fun <T : Any> Flow<T>.asPublisher(): JFlow.Publisher<T> {
30-
val reactivePublisher : org.reactivestreams.Publisher<T> = this.asPublisher<T>()
36+
@JvmOverloads // binary compatibility
37+
public fun <T : Any> Flow<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): JFlow.Publisher<T> {
38+
val reactivePublisher : org.reactivestreams.Publisher<T> = this.asPublisher<T>(context)
3139
return FlowAdapters.toFlowPublisher(reactivePublisher)
3240
}
3341

reactive/kotlinx-coroutines-reactive/api/kotlinx-coroutines-reactive.api

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class kotlinx/coroutines/reactive/FlowKt {
3232
public final class kotlinx/coroutines/reactive/FlowSubscription : kotlinx/coroutines/AbstractCoroutine, org/reactivestreams/Subscription {
3333
public final field flow Lkotlinx/coroutines/flow/Flow;
3434
public final field subscriber Lorg/reactivestreams/Subscriber;
35-
public fun <init> (Lkotlinx/coroutines/flow/Flow;Lorg/reactivestreams/Subscriber;)V
35+
public fun <init> (Lkotlinx/coroutines/flow/Flow;Lorg/reactivestreams/Subscriber;Lkotlin/coroutines/CoroutineContext;)V
3636
public fun cancel ()V
3737
public fun request (J)V
3838
}
@@ -65,5 +65,7 @@ public final class kotlinx/coroutines/reactive/PublisherCoroutine : kotlinx/coro
6565
public final class kotlinx/coroutines/reactive/ReactiveFlowKt {
6666
public static final fun asFlow (Lorg/reactivestreams/Publisher;)Lkotlinx/coroutines/flow/Flow;
6767
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;)Lorg/reactivestreams/Publisher;
68+
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Lorg/reactivestreams/Publisher;
69+
public static synthetic fun asPublisher$default (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Lorg/reactivestreams/Publisher;
6870
}
6971

0 commit comments

Comments
 (0)