Skip to content

Version 1.3.9 #2203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change log for kotlinx.coroutines

## Version 1.3.9

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

## Version 1.3.8

### New experimental features
Expand Down
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)
[![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)
[![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)

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

```kotlin
suspend fun main() = coroutineScope {
Expand Down Expand Up @@ -84,15 +84,15 @@ Add dependencies (you can also add other modules that you need):
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.3.8</version>
<version>1.3.9</version>
</dependency>
```

And make sure that you use the latest Kotlin version:

```xml
<properties>
<kotlin.version>1.3.71</kotlin.version>
<kotlin.version>1.4.0</kotlin.version>
</properties>
```

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

```groovy
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
}
```

And make sure that you use the latest Kotlin version:

```groovy
buildscript {
ext.kotlin_version = '1.3.71'
ext.kotlin_version = '1.4.0'
}
```

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

```groovy
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
}
```

And make sure that you use the latest Kotlin version:

```groovy
plugins {
kotlin("jvm") version "1.3.71"
kotlin("jvm") version "1.4.0"
}
```

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

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

### Android

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

```groovy
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
```

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

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

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

### Native

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

Only single-threaded code (JS-style) on Kotlin/Native is currently supported.
Expand Down
17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ buildscript {

repositories {
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven {
url "https://kotlin.bintray.com/kotlinx"
credentials {
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
}
}
maven {
url "https://kotlin.bintray.com/kotlin-dev"
credentials {
Expand Down Expand Up @@ -155,7 +161,14 @@ allprojects {
}
}
maven { url "https://kotlin.bintray.com/kotlin-eap" }
maven { url "https://kotlin.bintray.com/kotlinx" }
maven {
url "https://kotlin.bintray.com/kotlinx"
credentials {
username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
}
}
mavenLocal()
}
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#

# Kotlin
version=1.3.8-SNAPSHOT
version=1.3.9-SNAPSHOT
group=org.jetbrains.kotlinx
kotlin_version=1.3.71
kotlin_version=1.4.0

# Dependencies
junit_version=4.12
atomicfu_version=0.14.2
atomicfu_version=0.14.4
knit_version=0.1.3
html_version=0.6.8
lincheck_version=2.7.1
Expand Down Expand Up @@ -59,4 +59,4 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
# This is commented out, and the property is set conditionally in build.gradle, because 1.3.71 doesn't work with it.
# Once this property is set by default in new versions or 1.3.71 is dropped, either uncomment or remove this line.
#kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ public abstract interface class kotlinx/coroutines/channels/ReceiveChannel {
public abstract fun iterator ()Lkotlinx/coroutines/channels/ChannelIterator;
public abstract fun poll ()Ljava/lang/Object;
public abstract fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun receiveOrClosed (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun receiveOrClosed-ZYPwvRU (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun receiveOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ task jdk16Test(type: Test, dependsOn: [compileTestKotlinJvm, checkJdk16]) {
exclude '**/*LCStressTest.*' // lin-check tests use LinChecker which needs JDK8
exclude '**/exceptions/**' // exceptions tests check suppressed exception which needs JDK8
exclude '**/ExceptionsGuideTest.*'
exclude '**/RunInterruptibleStressTest.*' // fails on JDK 1.6 due to JDK bug
}

// Run these tests only during nightly stress test
Expand Down
6 changes: 2 additions & 4 deletions kotlinx-coroutines-core/common/src/CancellableContinuation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import kotlin.coroutines.intrinsics.*
*
* A [cancelled][isCancelled] continuation implies that it is [completed][isCompleted].
*
* Invocation of [resume] or [resumeWithException] in _resumed_ state produces an [IllegalStateException].
* Invocation of [resume] in _cancelled_ state is ignored (it is a trivial race between resume from the continuation owner and
* outer job's cancellation, and the cancellation wins).
* Invocation of [resumeWithException] in _cancelled_ state triggers exception handling of the passed exception.
* Invocation of [resume] or [resumeWithException] in _resumed_ state produces an [IllegalStateException],
* but is ignored in _cancelled_ state.
*
* ```
* +-----------+ resume +---------+
Expand Down
Binary file modified kotlinx-coroutines-core/jvm/resources/DebugProbesKt.bin
Binary file not shown.
24 changes: 13 additions & 11 deletions kotlinx-coroutines-core/jvm/test/RunInterruptibleStressTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ import org.junit.Test
import java.util.concurrent.atomic.*
import kotlin.test.*

/**
* Stress test for [runInterruptible].
* It does not pass on JDK 1.6 on Windows: [Thread.sleep] times out without being interrupted despite the
* fact that thread interruption flag is set.
*/
class RunInterruptibleStressTest : TestBase() {

@get:Rule
val dispatcher = ExecutorRule(4)
private val REPEAT_TIMES = 1000 * stressTestMultiplier
private val repeatTimes = 1000 * stressTestMultiplier

@Test
fun testStress() = runBlocking {
val interruptLeak = AtomicBoolean(false)
fun testStress() = runTest {
val enterCount = AtomicInteger(0)
val interruptedCount = AtomicInteger(0)

repeat(REPEAT_TIMES) {
repeat(repeatTimes) {
val job = launch(dispatcher) {
try {
runInterruptible {
enterCount.incrementAndGet()
try {
Thread.sleep(Long.MAX_VALUE)
Thread.sleep(10_000)
error("Sleep was not interrupted, Thread.isInterrupted=${Thread.currentThread().isInterrupted}")
} catch (e: InterruptedException) {
interruptedCount.incrementAndGet()
throw e
Expand All @@ -36,19 +40,17 @@ class RunInterruptibleStressTest : TestBase() {
} catch (e: CancellationException) {
// Expected
} finally {
interruptLeak.set(interruptLeak.get() || Thread.currentThread().isInterrupted)
assertFalse(Thread.currentThread().isInterrupted, "Interrupt flag should not leak")
}
}
// Add dispatch delay
val cancelJob = launch(dispatcher) {
job.cancel()
}

job.start()
joinAll(job, cancelJob)
}

assertFalse(interruptLeak.get())
println("Entered runInterruptible ${enterCount.get()} times")
assertTrue(enterCount.get() > 0) // ensure timing is Ok and we don't cancel it all prematurely
assertEquals(enterCount.get(), interruptedCount.get())
}
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-debug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ https://github.com/reactor/BlockHound/blob/1.0.2.RELEASE/docs/quick_start.md).
Add `kotlinx-coroutines-debug` to your project test dependencies:
```
dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.3.8'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.3.9'
}
```

Expand Down Expand Up @@ -61,7 +61,7 @@ stacktraces will be dumped to the console.
### Using as JVM agent

Debug module can also be used as a standalone JVM agent to enable debug probes on the application startup.
You can run your application with an additional argument: `-javaagent:kotlinx-coroutines-debug-1.3.8.jar`.
You can run your application with an additional argument: `-javaagent:kotlinx-coroutines-debug-1.3.9.jar`.
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.
When used as Java agent, `"kotlinx.coroutines.debug.enable.creation.stack.trace"` system property can be used to control
[DebugProbes.enableCreationStackTraces] along with agent startup.
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This package provides testing utilities for effectively testing coroutines.
Add `kotlinx-coroutines-test` to your project test dependencies:
```
dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.9'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public final class kotlinx/coroutines/jdk9/PublishKt {
public final class kotlinx/coroutines/jdk9/ReactiveFlowKt {
public static final fun asFlow (Ljava/util/concurrent/Flow$Publisher;)Lkotlinx/coroutines/flow/Flow;
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;)Ljava/util/concurrent/Flow$Publisher;
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Ljava/util/concurrent/Flow$Publisher;
public static synthetic fun asPublisher$default (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Ljava/util/concurrent/Flow$Publisher;
public static final fun collect (Ljava/util/concurrent/Flow$Publisher;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

14 changes: 11 additions & 3 deletions reactive/kotlinx-coroutines-jdk9/src/ReactiveFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

package kotlinx.coroutines.jdk9

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.reactive.asPublisher
import kotlinx.coroutines.reactive.collect
import org.reactivestreams.*
import kotlin.coroutines.*
import java.util.concurrent.Flow as JFlow
import org.reactivestreams.FlowAdapters

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class kotlinx/coroutines/reactive/FlowKt {
public final class kotlinx/coroutines/reactive/FlowSubscription : kotlinx/coroutines/AbstractCoroutine, org/reactivestreams/Subscription {
public final field flow Lkotlinx/coroutines/flow/Flow;
public final field subscriber Lorg/reactivestreams/Subscriber;
public fun <init> (Lkotlinx/coroutines/flow/Flow;Lorg/reactivestreams/Subscriber;)V
public fun <init> (Lkotlinx/coroutines/flow/Flow;Lorg/reactivestreams/Subscriber;Lkotlin/coroutines/CoroutineContext;)V
public fun cancel ()V
public fun request (J)V
}
Expand Down Expand Up @@ -65,5 +65,7 @@ public final class kotlinx/coroutines/reactive/PublisherCoroutine : kotlinx/coro
public final class kotlinx/coroutines/reactive/ReactiveFlowKt {
public static final fun asFlow (Lorg/reactivestreams/Publisher;)Lkotlinx/coroutines/flow/Flow;
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;)Lorg/reactivestreams/Publisher;
public static final fun asPublisher (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Lorg/reactivestreams/Publisher;
public static synthetic fun asPublisher$default (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;ILjava/lang/Object;)Lorg/reactivestreams/Publisher;
}

Loading