Skip to content

Commit c0bf01b

Browse files
authored
Merge pull request #2 from Kotlin/develop
Sync develop with parent project
2 parents 835ed4d + e8705fe commit c0bf01b

File tree

850 files changed

+13337
-11625
lines changed

Some content is hidden

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

850 files changed

+13337
-11625
lines changed

CHANGES.md

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

3+
## Version 1.3.5
4+
5+
* `firstOrNull` operator. Contributed by @bradynpoulsen.
6+
* `java.time` adapters for Flow operators. Contributed by @fvasco.
7+
* `kotlin.time.Duration` support (#1402). Contributed by @fvasco.
8+
* Memory leak with a mix of reusable and non-reusable continuations is fixed (#1855).
9+
* `DebugProbes` are ready for production installation: its performance is increased, the flag to disable creation stacktraces to reduce the footprint is introduced (#1379, #1372).
10+
* Stacktrace recovery workaround for Android 6.0 and earlier bug (#1866).
11+
* New integration module: `kotlinx-coroutines-jdk9` with adapters for `java.util.concurrent.Flow`.
12+
* `BroadcastChannel.close` properly starts lazy coroutine (#1713).
13+
* `kotlinx-coroutines-bom` is published without Gradle metadata.
14+
* Make calls to service loader in reactor integrations optimizable by R8 (#1817).
15+
16+
## Version 1.3.4
17+
18+
### Flow
19+
20+
* Detect missing `awaitClose` calls in `callbackFlow` to make it less error-prone when used with callbacks (#1762, #1770). This change makes `callbackFlow` **different** from `channelFlow`.
21+
* `ReceiveChannel.asFlow` extension is introduced (#1490).
22+
* Enforce exception transparency invariant in `flow` builder (#1657).
23+
* Proper `Dispatcher` support in `Flow` reactive integrations (#1765).
24+
* Batch `Subscription.request` calls in `Flow` reactive integration (#766).
25+
* `ObservableValue.asFlow` added to JavaFx integration module (#1695).
26+
* `ObservableSource.asFlow` added to RxJava2 integration module (#1768).
27+
28+
### Other changes
29+
30+
* `kotlinx-coroutines-core` is optimized for R8, making it much smaller for Android usages (75 KB for `1.3.4` release).
31+
* Performance of `Dispatchers.Default` is improved (#1704, #1706).
32+
* Kotlin is updated to 1.3.70.
33+
* `CoroutineDispatcher` and `ExecutorCoroutineDispatcher` experimental coroutine context keys are introduced (#1805).
34+
* Performance of various `Channel` operations is improved (#1565).
35+
36+
## Version 1.3.3
37+
38+
### Flow
39+
* `Flow.take` performance is significantly improved (#1538).
40+
* `Flow.merge` operator (#1491).
41+
* Reactive Flow adapters are promoted to stable API (#1549).
42+
* Reusable cancellable continuations were introduced that improved the performance of various flow operators and iteration over channels (#1534).
43+
* Fixed interaction of multiple flows with `take` operator (#1610).
44+
* Throw `NoSuchElementException` instead of `UnsupportedOperationException` for empty `Flow` in `reduce` operator (#1659).
45+
* `onCompletion` now rethrows downstream exceptions on emit attempt (#1654).
46+
* Allow non-emitting `withContext` from `flow` builder (#1616).
47+
48+
### Debugging
49+
50+
* `DebugProbes.dumpCoroutines` is optimized to be able to print the 6-digit number of coroutines (#1535).
51+
* Properly capture unstarted lazy coroutines in debugger (#1544).
52+
* Capture coroutines launched from within a test constructor with `CoroutinesTimeout` test rule (#1542).
53+
* Stacktraces of `Job`-related coroutine machinery are shortened and prettified (#1574).
54+
* Stacktrace recovery unification that should provide a consistent experience recover of stacktrace (#1597).
55+
* Stacktrace recovery for `withTimeout` is supported (#1625).
56+
* Do not recover exception with a single `String` parameter constructor that is not a `message` (#1631).
57+
58+
### Other features
59+
60+
* `Dispatchers.Default` and `Dispatchers.IO` rework: CPU consumption is significantly lower, predictable idle threads termination (#840, #1046, #1286).
61+
* Avoid `ServiceLoader` for loading `Dispatchers.Main` (#1572, #1557, #878, #1606).
62+
* Consistently handle undeliverable exceptions in RxJava and Reactor integrations (#252, #1614).
63+
* `yield` support in immediate dispatchers (#1474).
64+
* `CompletableDeferred.completeWith(result: Result<T>)` is introduced.
65+
* Added support for tvOS and watchOS-based Native targets (#1596).
66+
67+
### Bug fixes and improvements
68+
69+
* Kotlin version is updated to 1.3.61.
70+
* `CoroutineDispatcher.isDispatchNeeded` is promoted to stable API (#1014).
71+
* Livelock and stackoverflows in mutual `select` expressions are fixed (#1411, #504).
72+
* Properly handle `null` values in `ListenableFuture` integration (#1510).
73+
* Making ReceiveChannel.cancel linearizability-friendly.
74+
* Linearizability of Channel.close in a complex contended cases (#1419).
75+
* ArrayChannel.isBufferEmpty atomicity is fixed (#1526).
76+
* Various documentation improvements.
77+
* Reduced bytecode size of `kotlinx-coroutines-core`, reduced size of minified `dex` when using basic functionality of `kotlinx-coroutines`.
78+
79+
## Version 1.3.2
80+
81+
This is a maintenance release that does not include any new features or bug fixes.
82+
83+
* Reactive integrations for `Flow` are promoted to stable API.
84+
* Obsolete reactive API is deprecated.
85+
* Deprecation level for API deprecated in 1.3.0 is increased.
86+
* Various documentation improvements.
87+
388
## Version 1.3.1
489

590
This is a minor update with various fixes:

README.md

+25-21
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.1) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.3.1)
5+
[![Download](https://api.bintray.com/packages/kotlin/kotlinx/kotlinx.coroutines/images/download.svg?version=1.3.5) ](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.3.5)
66

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

1010
```kotlin
1111
suspend fun main() = coroutineScope {
@@ -45,8 +45,9 @@ suspend fun main() = coroutineScope {
4545
* [CoroutinesTimeout] test rule to automatically dump coroutines on test timeout.
4646
* [reactive](reactive/README.md) &mdash; modules that provide builders and iteration support for various reactive streams libraries:
4747
* Reactive Streams ([Publisher.collect], [Publisher.awaitSingle], [publish], etc),
48-
RxJava 2.x ([rxFlowable], [rxSingle], etc), and
49-
Project Reactor ([flux], [mono], etc).
48+
* Flow (JDK 9) (the same interface as for Reactive Streams),
49+
* RxJava 2.x ([rxFlowable], [rxSingle], etc), and
50+
* Project Reactor ([flux], [mono], etc).
5051
* [ui](ui/README.md) &mdash; modules that provide coroutine dispatchers for various single-threaded UI libraries:
5152
* Android, JavaFX, and Swing.
5253
* [integration](integration/README.md) &mdash; modules that provide integration with various asynchronous callback- and future-based libraries:
@@ -62,7 +63,6 @@ suspend fun main() = coroutineScope {
6263
* Guides and manuals:
6364
* [Guide to kotlinx.coroutines by example](https://kotlinlang.org/docs/reference/coroutines/coroutines-guide.html) (**read it first**)
6465
* [Guide to UI programming with coroutines](ui/coroutines-guide-ui.md)
65-
* [Guide to reactive streams with coroutines](reactive/coroutines-guide-reactive.md)
6666
* [Debugging capabilities in kotlinx.coroutines](docs/debugging.md)
6767
* [Compatibility policy and experimental annotations](docs/compatibility.md)
6868
* [Change log for kotlinx.coroutines](CHANGES.md)
@@ -83,15 +83,15 @@ Add dependencies (you can also add other modules that you need):
8383
<dependency>
8484
<groupId>org.jetbrains.kotlinx</groupId>
8585
<artifactId>kotlinx-coroutines-core</artifactId>
86-
<version>1.3.1</version>
86+
<version>1.3.5</version>
8787
</dependency>
8888
```
8989

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

9292
```xml
9393
<properties>
94-
<kotlin.version>1.3.50</kotlin.version>
94+
<kotlin.version>1.3.70</kotlin.version>
9595
</properties>
9696
```
9797

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

102102
```groovy
103103
dependencies {
104-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1'
104+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
105105
}
106106
```
107107

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

110110
```groovy
111111
buildscript {
112-
ext.kotlin_version = '1.3.50'
112+
ext.kotlin_version = '1.3.70'
113113
}
114114
```
115115

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

128128
```groovy
129129
dependencies {
130-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1")
130+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
131131
}
132132
```
133133

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

136136
```groovy
137137
plugins {
138-
kotlin("jvm") version "1.3.50"
138+
kotlin("jvm") version "1.3.70"
139139
}
140140
```
141141

@@ -146,7 +146,7 @@ Make sure that you have either `jcenter()` or `mavenCentral()` in the list of re
146146
Core modules of `kotlinx.coroutines` are also available for
147147
[Kotlin/JS](#js) and [Kotlin/Native](#native).
148148
In common code that should get compiled for different platforms, add dependency to
149-
[`kotlinx-coroutines-core-common`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-common/1.3.1/jar)
149+
[`kotlinx-coroutines-core-common`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-common/1.3.5/jar)
150150
(follow the link to get the dependency declaration snippet).
151151

152152
### Android
@@ -155,7 +155,7 @@ Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
155155
module as dependency when using `kotlinx.coroutines` on Android:
156156

157157
```groovy
158-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.1'
158+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
159159
```
160160

161161
This gives you access to Android [Dispatchers.Main]
@@ -165,24 +165,21 @@ threads are handled by Android runtime.
165165

166166
#### R8 and ProGuard
167167

168-
For R8 no actions required, it will take obfuscation rules from the jar.
169-
170-
For Proguard you need to add options from [coroutines.pro](kotlinx-coroutines-core/jvm/resources/META-INF/proguard/coroutines.pro) to your rules manually.
171-
172-
R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0 (3.3.0-beta also had it enabled).
168+
R8 and ProGuard rules are bundled into the [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android) module.
169+
For more details see ["Optimization" section for Android](ui/kotlinx-coroutines-android/README.md#optimization).
173170

174171
### JS
175172

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

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

182179
### Native
183180

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

188185
Only single-threaded code (JS-style) on Kotlin/Native is currently supported.
@@ -204,8 +201,9 @@ to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Grad
204201

205202
### Requirements
206203

207-
* JDK >= 1.8 referred to by the `JAVA_HOME` environment variable.
204+
* JDK >= 11 referred to by the `JAVA_HOME` environment variable.
208205
* JDK 1.6 referred to by the `JDK_16` environment variable. It is okay to have `JDK_16` pointing to `JAVA_HOME` for external contributions.
206+
* JDK 1.8 referred to by the `JDK_18` environment variable. Only used by nightly stress-tests. It is okay to have `JDK_16` pointing to `JAVA_HOME` for external contributions.
209207

210208
## Contributions and releases
211209

@@ -218,6 +216,12 @@ The `develop` branch is pushed to `master` during release.
218216

219217
* Full release procedure checklist is [here](RELEASE.md).
220218
* Steps for contributing new integration modules are explained [here](integration/README.md#Contributing).
219+
* Use [Knit](https://github.com/Kotlin/kotlinx-knit/blob/master/README.md) for updates to documentation:
220+
* In project root directory run `./gradlew knit`.
221+
* Commit updated documents and examples together with other changes.
222+
* Use [Binary Compatibility Validator](https://github.com/Kotlin/binary-compatibility-validator/blob/master/README.md) for updates to public API:
223+
* In project root directory run `./gradlew apiDump`.
224+
* Commit updated API index together with other changes.
221225

222226
<!--- MODULE kotlinx-coroutines-core -->
223227
<!--- INDEX kotlinx.coroutines -->

RELEASE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ To release new `<version>` of `kotlinx-coroutines`:
5353
* Create a release named `<version>`.
5454
* Cut & paste lines from [`CHANGES.md`](CHANGES.md) into description.
5555

56-
3. Build and publish documentation for web-site: <br>
56+
3. Build and publish documentation for web-site
57+
(make sure you have [Docker](https://www.docker.com/) installed first): <br>
5758
`site/deploy.sh <version> push`
5859

5960
4. In [Bintray](https://bintray.com/kotlin/kotlinx/kotlinx.coroutines) admin interface:

benchmarks/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44
sourceCompatibility = 1.8
55
targetCompatibility = 1.8
@@ -74,4 +74,6 @@ dependencies {
7474
compile "org.openjdk.jmh:jmh-core:1.21"
7575
compile 'com.typesafe.akka:akka-actor_2.12:2.5.0'
7676
compile project(':kotlinx-coroutines-core')
77+
// add jmh dependency on main
78+
jmh sourceSets.main.runtimeClasspath
7779
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# To run this script run the command 'python3 scripts/generate_plots_flow_flatten_merge.py' in the /benchmarks folder
2+
3+
4+
import pandas as pd
5+
import sys
6+
import locale
7+
import matplotlib.pyplot as plt
8+
from matplotlib.ticker import FormatStrFormatter
9+
10+
input_file = "build/reports/jmh/results.csv"
11+
output_file = "out/flow-flatten-merge.svg"
12+
# Please change the value of this variable according to the FlowFlattenMergeBenchmarkKt.ELEMENTS
13+
elements = 100000
14+
benchmark_name = "benchmarks.flow.FlowFlattenMergeBenchmark.flattenMerge"
15+
csv_columns = ["Benchmark", "Score", "Unit", "Param: concurrency", "Param: flowsNumberStrategy"]
16+
rename_columns = {"Benchmark": "benchmark", "Score" : "score", "Unit" : "unit",
17+
"Param: concurrency" : "concurrency", "Param: flowsNumberStrategy" : "flows"}
18+
19+
markers = ['.', 'v', '^', '1', '2', '8', 'p', 'P', 'x', 'D', 'd', 's']
20+
colours = ['red', 'gold', 'sienna', 'olivedrab', 'lightseagreen', 'navy', 'blue', 'm', 'crimson', 'yellow', 'orangered', 'slateblue', 'aqua', 'black', 'silver']
21+
22+
def next_colour():
23+
i = 0
24+
while True:
25+
yield colours[i % len(colours)]
26+
i += 1
27+
28+
def next_marker():
29+
i = 0
30+
while True:
31+
yield markers[i % len(markers)]
32+
i += 1
33+
34+
def draw(data, plt):
35+
plt.xscale('log', basex=2)
36+
plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%0.f'))
37+
plt.grid(linewidth='0.5', color='lightgray')
38+
if data.unit.unique()[0] != "ops/s":
39+
print("Unexpected time unit: " + data.unit.unique()[0])
40+
sys.exit(1)
41+
plt.ylabel("elements / ms")
42+
plt.xlabel('concurrency')
43+
plt.xticks(data.concurrency.unique())
44+
45+
colour_gen = next_colour()
46+
marker_gen = next_marker()
47+
for flows in data.flows.unique():
48+
gen_colour = next(colour_gen)
49+
gen_marker = next(marker_gen)
50+
res = data[(data.flows == flows)]
51+
# plt.plot(res.concurrency, res.score*elements/1000, label="flows={}".format(flows), color=gen_colour, marker=gen_marker)
52+
plt.errorbar(x=res.concurrency, y=res.score*elements/1000, yerr=res.score_error*elements/1000, solid_capstyle='projecting',
53+
label="flows={}".format(flows), capsize=4, color=gen_colour, linewidth=2.2)
54+
55+
langlocale = locale.getdefaultlocale()[0]
56+
locale.setlocale(locale.LC_ALL, langlocale)
57+
dp = locale.localeconv()['decimal_point']
58+
if dp == ",":
59+
csv_columns.append("Score Error (99,9%)")
60+
rename_columns["Score Error (99,9%)"] = "score_error"
61+
elif dp == ".":
62+
csv_columns.append("Score Error (99.9%)")
63+
rename_columns["Score Error (99.9%)"] = "score_error"
64+
else:
65+
print("Unexpected locale delimeter: " + dp)
66+
sys.exit(1)
67+
data = pd.read_csv(input_file, sep=",", decimal=dp)
68+
data = data[csv_columns].rename(columns=rename_columns)
69+
data = data[(data.benchmark == benchmark_name)]
70+
plt.rcParams.update({'font.size': 15})
71+
plt.figure(figsize=(12.5, 10))
72+
draw(data, plt)
73+
plt.legend(loc='upper center', borderpad=0, bbox_to_anchor=(0.5, 1.3), ncol=2, frameon=False, borderaxespad=2, prop={'size': 15})
74+
plt.tight_layout(pad=12, w_pad=2, h_pad=1)
75+
plt.savefig(output_file, bbox_inches='tight')

benchmarks/src/jmh/java/benchmarks/flow/scrabble/RxJava2PlaysScrabble.java

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

55
package benchmarks.flow.scrabble;
@@ -160,4 +160,4 @@ public List<Entry<Integer, List<String>>> play() throws Exception {
160160
.blockingGet() ;
161161
return finalList2 ;
162162
}
163-
}
163+
}

benchmarks/src/jmh/java/benchmarks/flow/scrabble/RxJava2PlaysScrabbleOpt.java

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

55
package benchmarks.flow.scrabble;
@@ -171,4 +171,4 @@ public List<Entry<Integer, List<String>>> play() throws Exception {
171171

172172
return finalList2 ;
173173
}
174-
}
174+
}

benchmarks/src/jmh/java/benchmarks/flow/scrabble/optimizations/FlowableCharSequence.java

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

55
package benchmarks.flow.scrabble.optimizations;

benchmarks/src/jmh/java/benchmarks/flow/scrabble/optimizations/FlowableSplit.java

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

55
package benchmarks.flow.scrabble.optimizations;

benchmarks/src/jmh/java/benchmarks/flow/scrabble/optimizations/StringFlowable.java

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

55
package benchmarks.flow.scrabble.optimizations;

0 commit comments

Comments
 (0)