Skip to content

Commit f4c5725

Browse files
committed
Merge branch 'master' into develop
2 parents 8eb8e68 + 412f585 commit f4c5725

17 files changed

+551
-436
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Bug report
3+
about: Our code behaves incorrectly?
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
**Double-check**
12+
13+
* Is this *really* a bug?
14+
- If the behavior is documented, but you disagree with it, please do file an issue, but as a "Design consideration," not a "Bug report."
15+
- If you don't understand why something behaves the way it does, consider asking on [StackOverflow](https://stackoverflow.com/) or the [Kotlin Slack](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up). The community is active and will likely clarify everything better than we could!
16+
* Is the problem not in some third-party library, not in [Kotlin](kotl.in/issue), or your own code—is it in the `kotlinx.coroutines` library itself?
17+
- Example: you write for Android, and your code works properly on most devices, but for a couple of them, it fails. Then please direct this to Google and/or the manufacturer of your device.
18+
* Maybe you're using some ancient version, and the problem doesn't happen with the latest releases of the compiler and the library?
19+
-->
20+
21+
**Describe the bug**
22+
23+
What happened? What should have happened instead?
24+
25+
**Provide a Reproducer**
26+
27+
* If possible, please provide a small self-contained project (or even just a single file) where the issue reproduces.
28+
* If you can't pinpoint the issue, please provide at least *some* project where this reproduces, for example, your production one. If you are not ready to show the project publicly, we are open to discussing the details privately.
29+
* If you really can't provide any code, please do still open an issue. This may prompt other people to chime in with their reproducers.

.github/ISSUE_TEMPLATE/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Kotlinlang Slack
4+
url: https://surveys.jetbrains.com/s3/kotlin-slack-sign-up
5+
about: Please ask and answer usage-related questions here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Design considerations
3+
about: We didn't think things through?
4+
title: ''
5+
labels: design
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
This is a place for issue reports that are not exactly bugs (wrong unintentional behavior) but for our library behaving suboptimally (though this could have been intentional).
12+
13+
**Double-check**
14+
15+
* If the behavior is strange, surprising, and undocumented, it could be a good idea to file a "Bug report" instead.
16+
* Is this still relevant with the latest version of the library? We could have changed this already.
17+
* Maybe there are good reasons for the existing behavior. Please try searching for existing discussions of the problem.
18+
* Are you using the right abstraction? Consider asking on [StackOverflow](https://stackoverflow.com/) or the [Kotlin Slack](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up). Maybe your need is better solved by some other abstraction entirely.
19+
20+
-->
21+
22+
**What do we have now?**
23+
24+
Preferably with specific code examples.
25+
26+
**What should be instead?**
27+
28+
Preferably with specific code examples.
29+
30+
**Why?**
31+
32+
The upsides of your proposal.
33+
* Who would benefit from this and how?
34+
- Would it be possible to cover new use cases?
35+
- Would some code become clearer?
36+
- Would the library become conceptually simpler?
37+
- etc.
38+
39+
**Why not?**
40+
41+
The downsides of your proposal that you already see.
42+
* Is this a breaking change?
43+
* Are there use cases that are better solved by what we have now?
44+
* Does some code become less clear after this change?
45+
* etc.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Feature request
3+
about: We're missing something?
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
**Double-check**
12+
13+
* Maybe this feature is already here?
14+
- Did you check the latest version of the library?
15+
- Maybe it's in a form you didn't expect? Consider asking on [StackOverflow](https://stackoverflow.com/) or the [Kotlin Slack](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up). The community will likely come up with some code that solves your need, and faster than it would take us to answer the issue!
16+
* Do you actually *need* this feature? Maybe restructuring your code would neatly eliminate the problem the feature would be solving.
17+
* Is the coroutines library the best place for this feature? Maybe it would be better suited for some third-party library?
18+
-->
19+
20+
**Use case**
21+
22+
Explain what *specifically* you are trying to do and why.
23+
- Example: "I have a `SharedFlow<Double>` that represents readings from an external device. The readings arrive in a set interval of 100 milliseconds. However, I also need to be able to calibrate the state of the external device by setting the readings from inside the program. When I set the state, the `SharedFlow<Double>` must immediately emit the value that was set and ignore any values coming from the device in the following 10 milliseconds since they are considered outdated, as the device is only guaranteed to recalibrate to the updated value after that period."
24+
- Non-example: "I have a `SharedFlow<T>` that has several sources of its values, and these sources need to have priorities attached to them so that one source always takes precedence over the other in a close race."
25+
- Non-example: "RxJava has feature X, so the coroutines library should also."
26+
27+
**The Shape of the API**
28+
29+
What could the desired API look like? What would some sample code using the new feature look like? If you don't have a clear idea, pseudocode or just explaining the API shape is also perfectly fine.
30+
31+
**Prior Art**
32+
33+
(Optional) Maybe you have seen something like the feature you need, but in other libraries, or there is something very similar but not quite sufficient in `kotlinx.coroutines`? Maybe there's already a way to do it, but it's too cumbersome and unclear?

CHANGES.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Note that this is a full changelog relative to 1.4.3 version. Changelog relative
223223
* `Flow.runningFold` operator (#2641).
224224
* `CoroutinesTimeout` rule for JUnit5 (#2197).
225225
* Internals of `Job` and `AbstractCoroutine` was reworked, resulting in smaller code size, less memory footprint, and better performance (#2513, #2512).
226-
* `CancellationException` from Kotlin standard library is used for cancellation on Koltin/JS and Kotlin/Native (#2638).
226+
* `CancellationException` from Kotlin standard library is used for cancellation on Kotlin/JS and Kotlin/Native (#2638).
227227
* Introduced new `DelicateCoroutinesApi` annotation that warns users about potential target API pitfalls and suggests studying API's documentation first. The only delicate API right now is `GlobalScope` (#2637).
228228
* Fixed bug introduced in `1.4.3` when `kotlinx-coroutines-core.jar` triggered IDEA debugger failure (#2619).
229229
* Fixed memory leak of `ChildHandlerNode` with reusable continuations (#2564).
@@ -264,7 +264,7 @@ Note that this is a full changelog relative to 1.4.3 version. Changelog relative
264264
* `Flow.runningFold` operator (#2641).
265265
* `CoroutinesTimeout` rule for JUnit5 (#2197).
266266
* Internals of `Job` and `AbstractCoroutine` was reworked, resulting in smaller code size, less memory footprint, and better performance (#2513, #2512).
267-
* `CancellationException` from Kotlin standard library is used for cancellation on Koltin/JS and Kotlin/Native (#2638).
267+
* `CancellationException` from Kotlin standard library is used for cancellation on Kotlin/JS and Kotlin/Native (#2638).
268268
* Introduced new `DelicateCoroutineApi` annotation that warns users about potential target API pitfalls and suggests studying API's documentation first. The only delicate API right now is `GlobalScope` (#2637).
269269
* Fixed bug introduced in `1.4.3` when `kotlinx-coroutines-core.jar` triggered IDEA debugger failure (#2619).
270270
* Fixed memory leak of `ChildHandlerNode` with reusable continuations (#2564).

CONTRIBUTING.md

+26-37
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,8 @@ fixes/changes/improvements via pull requests.
77

88
Both bug reports and feature requests are welcome.
99
Submit issues [here](https://github.com/Kotlin/kotlinx.coroutines/issues).
10-
11-
* Search for existing issues to avoid reporting duplicates.
12-
* When submitting a bug report:
13-
* Test it against the most recently released version. It might have been already fixed.
14-
* By default, we assume that your problem reproduces in Kotlin/JVM. Please, mention if the problem is
15-
specific to Kotlin/JS or Kotlin/Native.
16-
* Include the code that reproduces the problem. Provide the complete reproducer code, yet minimize it as much as possible.
17-
* However, don't put off reporting any weird or rarely appearing issues just because you cannot consistently
18-
reproduce them.
19-
* If the bug is in behavior, then explain what behavior you've expected and what you've got.
20-
* When submitting a feature request:
21-
* Explain why you need the feature &mdash; what's your use-case, what's your domain.
22-
* Explaining the problem you face is more important than suggesting a solution.
23-
Report your problem even if you don't have any proposed solution.
24-
* If there is an alternative way to do what you need, then show the code of the alternative.
10+
Questions about usage and general inquiries are better suited for [StackOverflow](https://stackoverflow.com)
11+
or the `#coroutines` channel in [KotlinLang Slack](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up).
2512

2613
## Submitting PRs
2714

@@ -30,21 +17,23 @@ However, please keep in mind that maintainers will have to support the resulting
3017
so do familiarize yourself with the following guidelines.
3118

3219
* All development (both new features and bug fixes) is performed in the `develop` branch.
33-
* The `master` branch always contains sources of the most recently released version.
34-
* Base PRs against the `develop` branch.
20+
* The `master` branch contains the sources of the most recently released version.
21+
* Base your PRs against the `develop` branch.
3522
* The `develop` branch is pushed to the `master` branch during release.
3623
* Documentation in markdown files can be updated directly in the `master` branch,
3724
unless the documentation is in the source code, and the patch changes line numbers.
3825
* If you fix documentation:
3926
* After fixing/changing code examples in the [`docs`](docs) folder or updating any references in the markdown files
4027
run the [Knit tool](#running-the-knit-tool) and commit the resulting changes as well.
41-
It will not pass the tests otherwise.
28+
The tests will not pass otherwise.
4229
* If you plan extensive rewrites/additions to the docs, then please [contact the maintainers](#contacting-maintainers)
43-
to coordinate the work in advance.
30+
to coordinate the work in advance.
4431
* If you make any code changes:
4532
* Follow the [Kotlin Coding Conventions](https://kotlinlang.org/docs/reference/coding-conventions.html).
4633
Use 4 spaces for indentation.
47-
* [Build the project](#building) to make sure it all works and passes the tests.
34+
Do not add extra newlines in function bodies: if you feel that blocks of code should be logically separated,
35+
then separate them with a comment instead.
36+
* [Build the project](#building) to make sure everything works and passes the tests.
4837
* If you fix a bug:
4938
* Write the test that reproduces the bug.
5039
* Fixes without tests are accepted only in exceptional circumstances if it can be shown that writing the
@@ -53,37 +42,37 @@ so do familiarize yourself with the following guidelines.
5342
name test functions as `testXxx`. Don't use backticks in test names.
5443
* If you introduce any new public APIs:
5544
* Comment on the existing issue if you want to work on it or create one beforehand.
56-
Ensure that the issue not only describes a problem, but also describes a solution that had received a positive feedback. Propose a solution if there isn't any.
57-
PRs with new API, but without a corresponding issue with a positive feedback about the proposed implementation are unlikely to
58-
be approved or reviewed.
45+
Ensure that not only the issue describes a problem, but also that the proposed solution has received positive
46+
feedback. Propose a solution if there isn't any.
47+
PRs that add new API without a corresponding issue with positive feedback about the proposed implementation are
48+
unlikely to be approved or reviewed.
5949
* All new APIs must come with documentation and tests.
60-
* All new APIs are initially released with `@ExperimentalCoroutineApi` annotation and are graduated later.
50+
* All new APIs are initially released with the `@ExperimentalCoroutineApi` annotation and graduate later.
6151
* [Update the public API dumps](#updating-the-public-api-dump) and commit the resulting changes as well.
6252
It will not pass the tests otherwise.
63-
* If you plan large API additions, then please start by submitting an issue with the proposed API design
53+
* If you plan large API additions, then please start by submitting an issue with the proposed API design
6454
to gather community feedback.
65-
* [Contact the maintainers](#contacting-maintainers) to coordinate any big piece of work in advance.
66-
* Steps for contributing new integration modules are explained [here](integration/README.md#Contributing).
55+
* [Contact the maintainers](#contacting-maintainers) to coordinate any extensive work in advance.
6756

6857
## Building
6958

7059
This library is built with Gradle.
7160

7261
* Run `./gradlew build` to build. It also runs all the tests.
73-
* Run `./gradlew <module>:test` to test the module you are looking at to speed
62+
* Run `./gradlew <module>:check` to test the module you are looking at to speed
7463
things up during development.
75-
* Run `./gradlew jvmTest` to perform only fast JVM tests of the core multiplatform module.
64+
* Run `./gradlew <module>:jvmTest` to perform only the fast JVM tests of a multiplatform module.
7665

7766
You can import this project into IDEA, but you have to delegate build actions
78-
to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)
67+
to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Build and run).
7968

8069
### Environment requirements
8170

8271
* JDK >= 11 referred to by the `JAVA_HOME` environment variable.
8372
* JDK 1.8 referred to by the `JDK_18` environment variable. Only used by nightly stress-tests.
84-
It is OK to have `JDK_18` to a non 1.8 JDK (e.g. `JAVA_HOME`) for external contributions.
73+
It is OK to have `JDK_18` point to a non-1.8 JDK (e.g. `JAVA_HOME`) for external contributions.
8574

86-
For external contributions you can for example add this to your shell startup scripts (e.g. `~/.zshrc`):
75+
For external contributions you can, for example, add this to your shell startup scripts (e.g. `~/.zshrc`):
8776
```shell
8877
# This assumes JAVA_HOME is set already to a JDK >= 11 version
8978
export JDK_18="$JAVA_HOME"
@@ -92,18 +81,18 @@ export JDK_18="$JAVA_HOME"
9281
### Running the Knit tool
9382

9483
* Use [Knit](https://github.com/Kotlin/kotlinx-knit/blob/main/README.md) for updates to documentation:
95-
* Run `./gradlew knit` to update example files, links, tables of content.
96-
* Commit updated documents and examples together with other changes.
84+
* Run `./gradlew knit` to update the example files, links, tables of content.
85+
* Commit the updated documents and examples together with other changes.
9786

9887
### Updating the public API dump
9988

100-
* Use [Binary Compatibility Validator](https://github.com/Kotlin/binary-compatibility-validator/blob/master/README.md) for updates to public API:
89+
* Use the [Binary Compatibility Validator](https://github.com/Kotlin/binary-compatibility-validator/blob/master/README.md) for updates to public API:
10190
* Run `./gradlew apiDump` to update API index files.
102-
* Commit updated API indexes together with other changes.
91+
* Commit the updated API indexes together with other changes.
10392

10493
## Releases
10594

106-
* Full release procedure checklist is [here](RELEASE.md).
95+
* The full release procedure checklist is [here](RELEASE.md).
10796

10897
## Contacting maintainers
10998

docs/cfg/buildprofiles.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<buildprofiles>
44
<variables>
55
<enable-browser-edits>true</enable-browser-edits>
6-
<browser-edits-url>https://github.com/Kotlin/kotlinx.coroutines/edit/master/</browser-edits-url>
6+
<browser-edits-url>https://github.com/Kotlin/kotlinx.coroutines/edit/master/docs/</browser-edits-url>
77
<allow-indexable-eaps>true</allow-indexable-eaps>
88
</variables>
99
<build-profile product="kc"/>
82.6 KB
Loading

docs/topics/cancellation-and-timeouts.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,11 @@ The timeout event in [withTimeout] is asynchronous with respect to the code runn
379379
even right before the return from inside of the timeout block. Keep this in mind if you open or acquire some
380380
resource inside the block that needs closing or release outside of the block.
381381

382-
For example, here we imitate a closeable resource with the `Resource` class, that simply keeps track of how many times
383-
it was created by incrementing the `acquired` counter and decrementing this counter from its `close` function.
384-
Let us run a lot of coroutines with the small timeout try acquire this resource from inside
385-
of the `withTimeout` block after a bit of delay and release it from outside.
382+
For example, here we imitate a closeable resource with the `Resource` class that simply keeps track of how many times
383+
it was created by incrementing the `acquired` counter and decrementing the counter in its `close` function.
384+
Now let us let us create a lot of coroutines, each of which creates a `Resource` at the end of the `withTimeout` block
385+
and releases the resource outside the block. We add a small delay so that it is more likely that the timeout occurs
386+
right when the `withTimeout` block is already finished, which will cause a resource leak.
386387

387388
```kotlin
388389
import kotlinx.coroutines.*
@@ -420,16 +421,16 @@ fun main() {
420421

421422
<!--- CLEAR -->
422423

423-
If you run the above code you'll see that it does not always print zero, though it may depend on the timings
424-
of your machine you may need to tweak timeouts in this example to actually see non-zero values.
424+
If you run the above code, you'll see that it does not always print zero, though it may depend on the timings
425+
of your machine. You may need to tweak the timeout in this example to actually see non-zero values.
425426

426-
> Note that incrementing and decrementing `acquired` counter here from 100K coroutines is completely safe,
427-
> since it always happens from the same main thread. More on that will be explained in the chapter
428-
> on coroutine context.
427+
> Note that incrementing and decrementing `acquired` counter here from 100K coroutines is completely thread-safe,
428+
> since it always happens from the same thread, the one used by `runBlocking`.
429+
> More on that will be explained in the chapter on coroutine context.
429430
>
430431
{type="note"}
431432

432-
To work around this problem you can store a reference to the resource in the variable as opposed to returning it
433+
To work around this problem you can store a reference to the resource in a variable instead of returning it
433434
from the `withTimeout` block.
434435

435436
```kotlin

0 commit comments

Comments
 (0)