Skip to content

Commit 08dff2c

Browse files
authored
Merge pull request #646 from Kotlin/version-0.30.1
Version 0.30.1
2 parents 7764e43 + a3826a9 commit 08dff2c

Some content is hidden

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

43 files changed

+662
-237
lines changed

CHANGES.md

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

3+
## Version 0.30.1
4+
Maintenance release:
5+
* Added `Dispatchers.Main` to common dispatchers, which can be used from Android, Swing and JavaFx projects if a corresponding integration library is added to dependencies.
6+
* With `Dispatchers.Main` improvement tooling bug in Android Studio #626 is mitigated, so Android users now can safely start the migration to the latest `kotlinx.coroutines` version.
7+
* Fixed bug with thread unsafety of shutdown sequence in `EventLoop`.
8+
* Experimental coroutine dispatcher now has `close` contract similar to Java `Executor`, so it can be safely instantiated and closed multiple times (affects only unit tests).
9+
* Atomicfu version is updated with fixes in JS transformer (see #609)
10+
311
## Version 0.30.0
412

513
* **[Major]** Further improvements in exception handling — no failure exception is lost.

COMPATIBILITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ stable public API, and thus `kotlinx.coroutines` is leaving its "experimental" s
1818
Version `1.0.0` (starting with its release candidate build) will have all its deprecated declarations removed and `kotlinx.coroutines.experimental` package will be renamed to `kotlinx.coroutines` without functional changes.
1919
In order to migrate `kotlinx.coroutines` to `1.0.0`, follow these steps:
2020

21-
1. Update `kotlinx.coroutines` to `0.30.0` version.
21+
1. Update `kotlinx.coroutines` to `0.30.1` version.
2222
2. Inspect compiler warnings about deprecated API and migrate it to a proposed alternative. Most of deprecated API has a corresponding replacement which can be applied from IDEA with quickfix.
23-
3. Update Kotlin version to `1.3.0` or to the latest `1.3.0-rc` and `kotlinx.coroutines` to version `0.30.0-eap13`. Then just get rid of `experimental` suffix in all imports.
23+
3. Update Kotlin version to `1.3.0` or to the latest `1.3.0-rc` and `kotlinx.coroutines` to version `0.30.1-eap13`. Then just get rid of `experimental` suffix in all imports.
2424
4. Update `kotlinx.coroutines` to version `1.0.0` or to the corresponding release candidate of it).
2525

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![official JetBrains project](http://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)](http://www.apache.org/licenses/LICENSE-2.0)
5-
[![Download](https://api.bintray.com/packages/kotlin/kotlinx/kotlinx.coroutines/images/download.svg?version=0.30.0) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/0.30.0)
5+
[![Download](https://api.bintray.com/packages/kotlin/kotlinx/kotlinx.coroutines/images/download.svg?version=0.30.1) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/0.30.1)
66

77
Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
88
This is a companion version for Kotlin 1.2.70 release.
@@ -21,9 +21,12 @@ GlobalScope.launch {
2121
* [common](common/README.md) — common coroutines across all backends:
2222
* `launch` and `async` coroutine builders;
2323
* `Job` and `Deferred` light-weight future with cancellation support;
24+
*` Dispatchers.Main` for UI dispatcher for Android, Swing and JavaFx;
2425
* `delay` and `yield` top-level suspending functions;
2526
* `Channel` and `Mutex` communication and synchronization primitives;
2627
* `produce` and `actor` coroutine builders;
28+
* `coroutineScope` and `supervisorScope` scope builders;
29+
* `SupervisorJob` for supervision of coroutines hierarchies;
2730
* `select` expression support and more.
2831
* [core](core/README.md) — Kotlin/JVM implementation of common coroutines with additional features:
2932
* `Dispatchers.IO` dispatcher for blocking coroutines.
@@ -39,8 +42,8 @@ GlobalScope.launch {
3942
## Documentation
4043

4144
* Presentations and videos:
42-
* [Introduction to Coroutines](https://www.youtube.com/watch?v=_hfBv0a09Jc) (Roman Elizarov at KotlinConf 2017, [slides](https://www.slideshare.net/elizarov/introduction-to-coroutines-kotlinconf-2017))
43-
* [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))
45+
* [Introduction to Coroutines](https://www.youtube.com/watch?v=_hfBv0a09Jc) (Roman Elizarov at KotlinConf 2017, [slides](https://www.slideshare.net/elizarov/introduction-to-coroutines-kotlinconf-2017))
46+
* [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))
4447
* Guides and manuals:
4548
* [Guide to kotlinx.coroutines by example](docs/coroutines-guide.md) (**read it first**)
4649
* [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md)
@@ -82,7 +85,7 @@ And make sure that you use the latest Kotlin version:
8285
Add dependencies (you can also add other modules that you need):
8386

8487
```groovy
85-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.0'
88+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.1'
8689
```
8790

8891
And make sure that you use the latest Kotlin version:
@@ -115,7 +118,7 @@ Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
115118
module as dependency when using `kotlinx.coroutines` on Android:
116119

117120
```groovy
118-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.0'
121+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.1'
119122
```
120123
This gives you access to Android [Dispatchers.Main](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-android/kotlinx.coroutines.experimental.android/kotlinx.coroutines.experimental.-dispatchers/index.html)
121124
coroutine dispatcher and also makes sure that in case of crashed coroutine with unhandled exception this

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-android.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public final class kotlinx/coroutines/experimental/android/HandlerContext : kotl
44
public final fun awaitFrame (Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
55
public fun dispatch (Lkotlin/coroutines/experimental/CoroutineContext;Ljava/lang/Runnable;)V
66
public fun equals (Ljava/lang/Object;)Z
7+
public synthetic fun getImmediate ()Lkotlinx/coroutines/experimental/MainCoroutineDispatcher;
78
public fun getImmediate ()Lkotlinx/coroutines/experimental/android/HandlerContext;
89
public synthetic fun getImmediate ()Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
910
public fun hashCode ()I
@@ -18,7 +19,7 @@ public final class kotlinx/coroutines/experimental/android/HandlerContextKt {
1819
public static final fun getUI ()Lkotlinx/coroutines/experimental/android/HandlerContext;
1920
}
2021

21-
public abstract class kotlinx/coroutines/experimental/android/HandlerDispatcher : kotlinx/coroutines/experimental/CoroutineDispatcher, kotlinx/coroutines/experimental/Delay {
22+
public abstract class kotlinx/coroutines/experimental/android/HandlerDispatcher : kotlinx/coroutines/experimental/MainCoroutineDispatcher, kotlinx/coroutines/experimental/Delay {
2223
public synthetic fun delay (JLjava/util/concurrent/TimeUnit;Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
2324
public fun delay (JLkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
2425
public abstract fun getImmediate ()Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
@@ -32,6 +33,6 @@ public final class kotlinx/coroutines/experimental/android/HandlerDispatcherKt {
3233
public static final fun from (Landroid/os/Handler;)Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
3334
public static final fun from (Landroid/os/Handler;Ljava/lang/String;)Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
3435
public static synthetic fun from$default (Landroid/os/Handler;Ljava/lang/String;ILjava/lang/Object;)Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
35-
public static final fun getMain (Lkotlinx/coroutines/experimental/Dispatchers;)Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
36+
public static final synthetic fun getMain (Lkotlinx/coroutines/experimental/Dispatchers;)Lkotlinx/coroutines/experimental/android/HandlerDispatcher;
3637
}
3738

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,15 @@ public final class kotlinx/coroutines/experimental/DispatchedTask$DefaultImpls {
314314
}
315315

316316
public final class kotlinx/coroutines/experimental/Dispatchers {
317-
public static final field Default Lkotlinx/coroutines/experimental/CoroutineDispatcher;
318317
public static final field INSTANCE Lkotlinx/coroutines/experimental/Dispatchers;
319-
public static final field Unconfined Lkotlinx/coroutines/experimental/CoroutineDispatcher;
318+
public static final fun getDefault ()Lkotlinx/coroutines/experimental/CoroutineDispatcher;
319+
public static final fun getIO ()Lkotlinx/coroutines/experimental/CoroutineDispatcher;
320+
public static final fun getMain ()Lkotlinx/coroutines/experimental/MainCoroutineDispatcher;
321+
public static final fun getUnconfined ()Lkotlinx/coroutines/experimental/CoroutineDispatcher;
320322
}
321323

322324
public final class kotlinx/coroutines/experimental/DispatchersKt {
323325
public static final field IO_PARALLELISM_PROPERTY_NAME Ljava/lang/String;
324-
public static final fun getIO (Lkotlinx/coroutines/experimental/Dispatchers;)Lkotlinx/coroutines/experimental/CoroutineDispatcher;
325326
}
326327

327328
public abstract interface class kotlinx/coroutines/experimental/DisposableHandle {
@@ -468,6 +469,11 @@ public final class kotlinx/coroutines/experimental/LazyDeferredKt {
468469
public static final fun lazyDefer (Lkotlin/coroutines/experimental/CoroutineContext;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/experimental/Deferred;
469470
}
470471

472+
public abstract class kotlinx/coroutines/experimental/MainCoroutineDispatcher : kotlinx/coroutines/experimental/CoroutineDispatcher {
473+
public fun <init> ()V
474+
public abstract fun getImmediate ()Lkotlinx/coroutines/experimental/MainCoroutineDispatcher;
475+
}
476+
471477
public final class kotlinx/coroutines/experimental/NonCancellable : kotlin/coroutines/experimental/AbstractCoroutineContextElement, kotlinx/coroutines/experimental/Job {
472478
public static final field INSTANCE Lkotlinx/coroutines/experimental/NonCancellable;
473479
public fun attachChild (Lkotlinx/coroutines/experimental/ChildJob;)Lkotlinx/coroutines/experimental/ChildHandle;

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-javafx.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
public final class kotlinx/coroutines/experimental/javafx/JavaFx : kotlinx/coroutines/experimental/javafx/JavaFxDispatcher {
22
public static final field INSTANCE Lkotlinx/coroutines/experimental/javafx/JavaFx;
33
public final fun awaitPulse (Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
4-
public fun dispatch (Lkotlin/coroutines/experimental/CoroutineContext;Ljava/lang/Runnable;)V
5-
public fun invokeOnTimeout (JLjava/lang/Runnable;)Lkotlinx/coroutines/experimental/DisposableHandle;
6-
public fun scheduleResumeAfterDelay (JLkotlinx/coroutines/experimental/CancellableContinuation;)V
4+
public fun getImmediate ()Lkotlinx/coroutines/experimental/MainCoroutineDispatcher;
75
public fun toString ()Ljava/lang/String;
86
}
97

10-
public abstract class kotlinx/coroutines/experimental/javafx/JavaFxDispatcher : kotlinx/coroutines/experimental/CoroutineDispatcher, kotlinx/coroutines/experimental/Delay {
8+
public abstract class kotlinx/coroutines/experimental/javafx/JavaFxDispatcher : kotlinx/coroutines/experimental/MainCoroutineDispatcher, kotlinx/coroutines/experimental/Delay {
119
public synthetic fun delay (JLjava/util/concurrent/TimeUnit;Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
1210
public fun delay (JLkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
11+
public fun dispatch (Lkotlin/coroutines/experimental/CoroutineContext;Ljava/lang/Runnable;)V
1312
public fun invokeOnTimeout (JLjava/lang/Runnable;)Lkotlinx/coroutines/experimental/DisposableHandle;
1413
public synthetic fun invokeOnTimeout (JLjava/util/concurrent/TimeUnit;Ljava/lang/Runnable;)Lkotlinx/coroutines/experimental/DisposableHandle;
1514
public synthetic fun scheduleResumeAfterDelay (JLjava/util/concurrent/TimeUnit;Lkotlinx/coroutines/experimental/CancellableContinuation;)V
15+
public fun scheduleResumeAfterDelay (JLkotlinx/coroutines/experimental/CancellableContinuation;)V
1616
}
1717

1818
public final class kotlinx/coroutines/experimental/javafx/JavaFxDispatcherKt {

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-swing.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
public final class kotlinx/coroutines/experimental/swing/Swing : kotlinx/coroutines/experimental/swing/SwingDispatcher {
22
public static final field INSTANCE Lkotlinx/coroutines/experimental/swing/Swing;
3-
public fun dispatch (Lkotlin/coroutines/experimental/CoroutineContext;Ljava/lang/Runnable;)V
4-
public fun invokeOnTimeout (JLjava/lang/Runnable;)Lkotlinx/coroutines/experimental/DisposableHandle;
5-
public fun scheduleResumeAfterDelay (JLkotlinx/coroutines/experimental/CancellableContinuation;)V
3+
public fun getImmediate ()Lkotlinx/coroutines/experimental/MainCoroutineDispatcher;
64
public fun toString ()Ljava/lang/String;
75
}
86

9-
public abstract class kotlinx/coroutines/experimental/swing/SwingDispatcher : kotlinx/coroutines/experimental/CoroutineDispatcher, kotlinx/coroutines/experimental/Delay {
7+
public abstract class kotlinx/coroutines/experimental/swing/SwingDispatcher : kotlinx/coroutines/experimental/MainCoroutineDispatcher, kotlinx/coroutines/experimental/Delay {
108
public synthetic fun delay (JLjava/util/concurrent/TimeUnit;Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
119
public fun delay (JLkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;
10+
public fun dispatch (Lkotlin/coroutines/experimental/CoroutineContext;Ljava/lang/Runnable;)V
1211
public fun invokeOnTimeout (JLjava/lang/Runnable;)Lkotlinx/coroutines/experimental/DisposableHandle;
1312
public synthetic fun invokeOnTimeout (JLjava/util/concurrent/TimeUnit;Ljava/lang/Runnable;)Lkotlinx/coroutines/experimental/DisposableHandle;
1413
public synthetic fun scheduleResumeAfterDelay (JLjava/util/concurrent/TimeUnit;Lkotlinx/coroutines/experimental/CancellableContinuation;)V
14+
public fun scheduleResumeAfterDelay (JLkotlinx/coroutines/experimental/CancellableContinuation;)V
1515
}
1616

1717
public final class kotlinx/coroutines/experimental/swing/SwingDispatcherKt {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ internal abstract class AbstractContinuation<in T>(
105105
/**
106106
* It is used when parent is cancelled to get the cancellation cause for this continuation.
107107
*/
108-
open fun getParentCancellationCause(parent: Job): Throwable =
108+
open fun getContinuationCancellationCause(parent: Job): Throwable =
109109
parent.getCancellationException()
110110

111111
private fun trySuspend(): Boolean {

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

+24-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
package kotlinx.coroutines.experimental
66

7-
import kotlinx.coroutines.experimental.internal.*
87
import kotlin.coroutines.experimental.*
98

109
/**
1110
* Groups various implementations of [CoroutineDispatcher].
1211
*/
13-
public object Dispatchers {
12+
expect object Dispatchers {
1413
/**
1514
* The default [CoroutineDispatcher] that is used by all standard builders like
1615
* [launch][CoroutineScope.launch], [async][CoroutineScope.async], etc
@@ -19,9 +18,27 @@ public object Dispatchers {
1918
* It is backed by a shared pool of threads on JVM. By default, the maximal number of threads used
2019
* by this dispatcher is equal to the number CPU cores, but is at least two.
2120
*/
22-
@JvmField
23-
public val Default: CoroutineDispatcher =
24-
createDefaultDispatcher()
21+
public val Default: CoroutineDispatcher
22+
23+
/**
24+
* A coroutine dispatcher that is confined to the Main thread operating with UI objects.
25+
* Usually such dispatcher is single-threaded.
26+
*
27+
* Access to this property may throw [IllegalStateException] if no main dispatchers are present in the classpath.
28+
*
29+
* Depending on platform and classpath it can be mapped to different dispatchers:
30+
* - On JS and Native it is equivalent of [Default] dispatcher.
31+
* - On JVM it either Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by
32+
* [`ServiceLoader`](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html).
33+
*
34+
* In order to work with `Main` dispatcher, following artifact should be added to project runtime dependencies:
35+
* - `kotlinx-coroutines-android` for Android Main thread dispatcher
36+
* - `kotlinx-coroutines-javafx` for JavaFx Application thread dispatcher
37+
* - `kotlinx-coroutines-swing` for Swing EDT dispatcher
38+
*
39+
* Implementation note: [MainCoroutineDispatcher.immediate] is not supported on Native and JS platforms.
40+
*/
41+
public val Main: MainCoroutineDispatcher
2542

2643
/**
2744
* A coroutine dispatcher that is not confined to any specific thread.
@@ -39,8 +56,6 @@ public object Dispatchers {
3956
* **Note: This is an experimental api.**
4057
* Semantics, order of execution, and particular implementation details of this dispatcher may change in the future.
4158
*/
42-
@JvmField
4359
@ExperimentalCoroutinesApi
44-
public val Unconfined: CoroutineDispatcher =
45-
kotlinx.coroutines.experimental.Unconfined
46-
}
60+
public val Unconfined: CoroutineDispatcher
61+
}

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

+19-2
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,30 @@ public inline fun DisposableHandle(crossinline block: () -> Unit) =
425425
internal interface ChildJob : Job {
426426
/**
427427
* Parent is cancelling its child by invoking this method.
428-
* Child finds the cancellation cause using [getCancellationException] of the [parentJob].
428+
* Child finds the cancellation cause using [ParentJob.getChildJobCancellationCause].
429429
* This method does nothing is the child is already being cancelled.
430430
*
431431
* @suppress **This is unstable API and it is subject to change.**
432432
*/
433433
@InternalCoroutinesApi
434-
public fun parentCancelled(parentJob: Job)
434+
public fun parentCancelled(parentJob: ParentJob)
435+
}
436+
437+
/**
438+
* A reference that child receives from its parent when it is being cancelled by the parent.
439+
*
440+
* @suppress **This is unstable API and it is subject to change.**
441+
*/
442+
@InternalCoroutinesApi
443+
internal interface ParentJob : Job {
444+
/**
445+
* Child job is using this method to learn its cancellation cause when the parent cancels it with [ChildJob.parentCancelled].
446+
* This method is invoked only if the child was not already being cancelled.
447+
*
448+
* @suppress **This is unstable API and it is subject to change.**
449+
*/
450+
@InternalCoroutinesApi
451+
public fun getChildJobCancellationCause(): Throwable
435452
}
436453

437454
/**

0 commit comments

Comments
 (0)