Skip to content

Commit 24d5fee

Browse files
committed
Merge branch 'master' into develop
2 parents 2032033 + 4116d4a commit 24d5fee

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

docs/topics/cancellation-and-timeouts.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ resource inside the block that needs closing or release outside of the block.
381381

382382
For example, here we imitate a closeable resource with the `Resource` class that simply keeps track of how many times
383383
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
384+
Now let us create a lot of coroutines, each of which creates a `Resource` at the end of the `withTimeout` block
385385
and releases the resource outside the block. We add a small delay so that it is more likely that the timeout occurs
386386
right when the `withTimeout` block is already finished, which will cause a resource leak.
387387

@@ -398,7 +398,7 @@ class Resource {
398398

399399
fun main() {
400400
runBlocking {
401-
repeat(100_000) { // Launch 100K coroutines
401+
repeat(10_000) { // Launch 10K coroutines
402402
launch {
403403
val resource = withTimeout(60) { // Timeout of 60 ms
404404
delay(50) // Delay for 50 ms
@@ -446,7 +446,7 @@ class Resource {
446446
fun main() {
447447
//sampleStart
448448
runBlocking {
449-
repeat(100_000) { // Launch 100K coroutines
449+
repeat(10_000) { // Launch 10K coroutines
450450
launch {
451451
var resource: Resource? = null // Not acquired yet
452452
try {

docs/topics/coroutines-and-channels.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ is to use _callbacks_.
215215
Instead of calling the code that should be invoked right after the operation is completed, you can extract it
216216
into a separate callback, often a lambda, and pass that lambda to the caller in order for it to be called later.
217217
218-
To make the UI responsive, you can either move the whole computation to a separate thread or switch to the Retrofit API,
218+
To make the UI responsive, you can either move the whole computation to a separate thread or switch to the Retrofit API
219219
which uses callbacks instead of blocking calls.
220220
221221
### Use a background thread
@@ -905,7 +905,7 @@ the parent coroutine.
905905
req: RequestData
906906
): List<User> = coroutineScope {
907907
// ...
908-
GlobalScope.async {
908+
async {
909909
log("starting loading for ${repo.name}")
910910
delay(3000)
911911
// load repo contributors

docs/topics/coroutines-guide.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[//]: # (title: Coroutines guide)
22

3-
Kotlin, as a language, provides only minimal low-level APIs in its standard library to enable various other
3+
Kotlin provides only minimal low-level APIs in its standard library to enable other
44
libraries to utilize coroutines. Unlike many other languages with similar capabilities, `async` and `await`
55
are not keywords in Kotlin and are not even part of its standard library. Moreover, Kotlin's concept
66
of _suspending function_ provides a safer and less error-prone abstraction for asynchronous
77
operations than futures and promises.
88

99
`kotlinx.coroutines` is a rich library for coroutines developed by JetBrains. It contains a number of high-level
10-
coroutine-enabled primitives that this guide covers, including `launch`, `async` and others.
10+
coroutine-enabled primitives that this guide covers, including `launch`, `async`, and others.
1111

12-
This is a guide on core features of `kotlinx.coroutines` with a series of examples, divided up into different topics.
12+
This is a guide about the core features of `kotlinx.coroutines` with a series of examples, divided up into different topics.
1313

1414
In order to use coroutines as well as follow the examples in this guide, you need to add a dependency on the `kotlinx-coroutines-core` module as explained
1515
[in the project README](https://github.com/Kotlin/kotlinx.coroutines/blob/master/README.md#using-in-your-projects).

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public expect object Dispatchers {
5757
* ```
5858
* withContext(Dispatchers.Unconfined) {
5959
* println(1)
60-
* withContext(Dispatchers.Unconfined) { // Nested unconfined
60+
* launch(Dispatchers.Unconfined) { // Nested unconfined
6161
* println(2)
6262
* }
6363
* println(3)
6464
* }
6565
* println("Done")
6666
* ```
6767
* Can print both "1 2 3" and "1 3 2". This is an implementation detail that can be changed.
68-
* However, it is guaranteed that "Done" will be printed only when both `withContext` calls are completed.
68+
* However, it is guaranteed that "Done" will only be printed once the code in both `withContext` and `launch` completes.
6969
*
7070
* If you need your coroutine to be confined to a particular thread or a thread-pool after resumption,
7171
* but still want to execute it in the current call-frame until its first suspension, you can use

kotlinx-coroutines-core/concurrent/src/channels/Channels.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import kotlin.jvm.*
3030
public fun <E> SendChannel<E>.trySendBlocking(element: E): ChannelResult<Unit> {
3131
/*
3232
* Sent successfully -- bail out.
33-
* But failure may indicate either that the channel it full or that
33+
* But failure may indicate either that the channel is full or that
3434
* it is close. Go to slow path on failure to simplify the successful path and
3535
* to materialize default exception.
3636
*/

kotlinx-coroutines-core/jvm/src/Interruptible.kt

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

55
package kotlinx.coroutines
@@ -8,7 +8,8 @@ import kotlinx.atomicfu.*
88
import kotlin.coroutines.*
99

1010
/**
11-
* Calls the specified [block] with a given coroutine context in an interruptible manner.
11+
* Calls the specified [block] with a given coroutine context in
12+
* [an interruptible manner](https://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html).
1213
* The blocking code block will be interrupted and this function will throw [CancellationException]
1314
* if the coroutine is cancelled.
1415
*

kotlinx-coroutines-core/jvm/test/guide/example-cancel-09.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Resource {
1616

1717
fun main() {
1818
runBlocking {
19-
repeat(100_000) { // Launch 100K coroutines
19+
repeat(10_000) { // Launch 10K coroutines
2020
launch {
2121
val resource = withTimeout(60) { // Timeout of 60 ms
2222
delay(50) // Delay for 50 ms

kotlinx-coroutines-core/jvm/test/guide/example-cancel-10.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Resource {
1616

1717
fun main() {
1818
runBlocking {
19-
repeat(100_000) { // Launch 100K coroutines
19+
repeat(10_000) { // Launch 10K coroutines
2020
launch {
2121
var resource: Resource? = null // Not acquired yet
2222
try {

0 commit comments

Comments
 (0)