Skip to content

Commit 310f8b7

Browse files
committed
Merge remote-tracking branch 'origin/master' into develop
2 parents 445e798 + 69c26df commit 310f8b7

Some content is hidden

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

54 files changed

+231
-230
lines changed

CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Visible consequences of include more robust exception handling for large corouti
215215
* Distribution no longer uses multi-version jar which is not supported on Android (see #510).
216216
* JS version of the library does not depend on AtomicFu anymore:
217217
  All the atomic boxes in JS are fully erased.
218-
* Note, that versions 0.25.1-2 are skipped for technical reasons (they were not fully released).
218+
* Note that versions 0.25.1-2 are skipped for technical reasons (they were not fully released).
219219

220220
## Version 0.25.0
221221

RELEASE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ To release new `<version>` of `kotlinx-coroutines`:
5050
* Run "Deploy (Configure, RUN THIS ONE)" configuration with the corresponding new version.
5151

5252
2. In [GitHub](https://github.com/kotlin/kotlinx.coroutines) interface:
53-
* Create new release named as `<version>`.
53+
* Create a release named `<version>`.
5454
* Cut & paste lines from [`CHANGES.md`](CHANGES.md) into description.
5555

5656
3. Build and publish documentation for web-site: <br>

docs/basics.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Run the following code:
4747
import kotlinx.coroutines.*
4848

4949
fun main() {
50-
GlobalScope.launch { // launch new coroutine in background and continue
50+
GlobalScope.launch { // launch a new coroutine in background and continue
5151
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
5252
println("World!") // print after delay
5353
}
@@ -58,7 +58,7 @@ fun main() {
5858

5959
</div>
6060

61-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt)
61+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt).
6262
6363
You will see the following result:
6464

@@ -98,7 +98,7 @@ Let's be explicit about blocking using [runBlocking] coroutine builder:
9898
import kotlinx.coroutines.*
9999

100100
fun main() {
101-
GlobalScope.launch { // launch new coroutine in background and continue
101+
GlobalScope.launch { // launch a new coroutine in background and continue
102102
delay(1000L)
103103
println("World!")
104104
}
@@ -111,15 +111,15 @@ fun main() {
111111

112112
</div>
113113

114-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt)
114+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt).
115115
116116
<!--- TEST
117117
Hello,
118118
World!
119119
-->
120120

121121
The result is the same, but this code uses only non-blocking [delay].
122-
The main thread, that invokes `runBlocking`, _blocks_ until the coroutine inside `runBlocking` completes.
122+
The main thread invoking `runBlocking` _blocks_ until the coroutine inside `runBlocking` completes.
123123

124124
This example can be also rewritten in a more idiomatic way, using `runBlocking` to wrap
125125
the execution of the main function:
@@ -130,7 +130,7 @@ the execution of the main function:
130130
import kotlinx.coroutines.*
131131

132132
fun main() = runBlocking<Unit> { // start main coroutine
133-
GlobalScope.launch { // launch new coroutine in background and continue
133+
GlobalScope.launch { // launch a new coroutine in background and continue
134134
delay(1000L)
135135
println("World!")
136136
}
@@ -141,7 +141,7 @@ fun main() = runBlocking<Unit> { // start main coroutine
141141

142142
</div>
143143

144-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt)
144+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt).
145145
146146
<!--- TEST
147147
Hello,
@@ -151,7 +151,7 @@ World!
151151
Here `runBlocking<Unit> { ... }` works as an adaptor that is used to start the top-level main coroutine.
152152
We explicitly specify its `Unit` return type, because a well-formed `main` function in Kotlin has to return `Unit`.
153153

154-
This is also a way to write unit-tests for suspending functions:
154+
This is also a way to write unit tests for suspending functions:
155155

156156
<!--- INCLUDE
157157
import kotlinx.coroutines.*
@@ -184,7 +184,7 @@ import kotlinx.coroutines.*
184184

185185
fun main() = runBlocking {
186186
//sampleStart
187-
val job = GlobalScope.launch { // launch new coroutine and keep a reference to its Job
187+
val job = GlobalScope.launch { // launch a new coroutine and keep a reference to its Job
188188
delay(1000L)
189189
println("World!")
190190
}
@@ -196,7 +196,7 @@ fun main() = runBlocking {
196196

197197
</div>
198198

199-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt)
199+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt).
200200
201201
<!--- TEST
202202
Hello,
@@ -209,11 +209,11 @@ the background job in any way. Much better.
209209
### Structured concurrency
210210

211211
There is still something to be desired for practical usage of coroutines.
212-
When we use `GlobalScope.launch` we create a top-level coroutine. Even though it is light-weight, it still
212+
When we use `GlobalScope.launch`, we create a top-level coroutine. Even though it is light-weight, it still
213213
consumes some memory resources while it runs. If we forget to keep a reference to the newly launched
214214
coroutine it still runs. What if the code in the coroutine hangs (for example, we erroneously
215215
delay for too long), what if we launched too many coroutines and ran out of memory?
216-
Having to manually keep a reference to all the launched coroutines and [join][Job.join] them is error-prone.
216+
Having to manually keep references to all the launched coroutines and [join][Job.join] them is error-prone.
217217

218218
There is a better solution. We can use structured concurrency in our code.
219219
Instead of launching coroutines in the [GlobalScope], just like we usually do with threads (threads are always global),
@@ -231,7 +231,7 @@ in its scope complete. Thus, we can make our example simpler:
231231
import kotlinx.coroutines.*
232232

233233
fun main() = runBlocking { // this: CoroutineScope
234-
launch { // launch new coroutine in the scope of runBlocking
234+
launch { // launch a new coroutine in the scope of runBlocking
235235
delay(1000L)
236236
println("World!")
237237
}
@@ -241,7 +241,7 @@ fun main() = runBlocking { // this: CoroutineScope
241241

242242
</div>
243243

244-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt)
244+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt).
245245
246246
<!--- TEST
247247
Hello,
@@ -250,7 +250,7 @@ World!
250250

251251
### Scope builder
252252
In addition to the coroutine scope provided by different builders, it is possible to declare your own scope using
253-
[coroutineScope] builder. It creates new coroutine scope and does not complete until all launched children
253+
[coroutineScope] builder. It creates a coroutine scope and does not complete until all launched children
254254
complete. The main difference between [runBlocking] and [coroutineScope] is that the latter does not block the current thread
255255
while waiting for all children to complete.
256256

@@ -265,23 +265,23 @@ fun main() = runBlocking { // this: CoroutineScope
265265
println("Task from runBlocking")
266266
}
267267

268-
coroutineScope { // Creates a new coroutine scope
268+
coroutineScope { // Creates a coroutine scope
269269
launch {
270270
delay(500L)
271271
println("Task from nested launch")
272272
}
273273

274274
delay(100L)
275-
println("Task from coroutine scope") // This line will be printed before nested launch
275+
println("Task from coroutine scope") // This line will be printed before the nested launch
276276
}
277277

278-
println("Coroutine scope is over") // This line is not printed until nested launch completes
278+
println("Coroutine scope is over") // This line is not printed until the nested launch completes
279279
}
280280
```
281281

282282
</div>
283283

284-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt)
284+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt).
285285
286286
<!--- TEST
287287
Task from coroutine scope
@@ -317,7 +317,7 @@ suspend fun doWorld() {
317317

318318
</div>
319319

320-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt)
320+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt).
321321
322322
<!--- TEST
323323
Hello,
@@ -328,10 +328,10 @@ World!
328328
But what if the extracted function contains a coroutine builder which is invoked on the current scope?
329329
In this case `suspend` modifier on the extracted function is not enough. Making `doWorld` extension
330330
method on `CoroutineScope` is one of the solutions, but it may not always be applicable as it does not make API clearer.
331-
Idiomatic solution is to have either explicit `CoroutineScope` as a field in a class containing target function
332-
or implicit when outer class implements `CoroutineScope`.
331+
The idiomatic solution is to have either an explicit `CoroutineScope` as a field in a class containing the target function
332+
or an implicit one when the outer class implements `CoroutineScope`.
333333
As a last resort, [CoroutineScope(coroutineContext)][CoroutineScope()] can be used, but such approach is structurally unsafe
334-
because you no longer have control on the scope this method is executed. Only private API can use this builder.
334+
because you no longer have control on the scope of execution of this method. Only private APIs can use this builder.
335335

336336
### Coroutines ARE light-weight
337337

@@ -354,7 +354,7 @@ fun main() = runBlocking {
354354

355355
</div>
356356

357-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt)
357+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt).
358358
359359
<!--- TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->
360360

@@ -386,7 +386,7 @@ fun main() = runBlocking {
386386

387387
</div>
388388

389-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt)
389+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt).
390390
391391
You can run and see that it prints three lines and terminates:
392392

docs/cancellation-and-timeouts.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fun main() = runBlocking {
6464

6565
</div>
6666

67-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt)
67+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt).
6868
6969
It produces the following output:
7070

@@ -119,7 +119,7 @@ fun main() = runBlocking {
119119

120120
</div>
121121

122-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-02.kt)
122+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-02.kt).
123123
124124
Run it to see that it continues to print "I'm sleeping" even after cancellation
125125
until the job completes by itself after five iterations.
@@ -171,7 +171,7 @@ fun main() = runBlocking {
171171

172172
</div>
173173

174-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt)
174+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt).
175175
176176
As you can see, now this loop is cancelled. [isActive] is an extension property that is
177177
available inside the code of coroutine via [CoroutineScope] object.
@@ -218,7 +218,7 @@ fun main() = runBlocking {
218218

219219
</div>
220220

221-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-04.kt)
221+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-04.kt).
222222
223223
Both [join][Job.join] and [cancelAndJoin] wait for all the finalization actions to complete,
224224
so the example above produces the following output:
@@ -274,7 +274,7 @@ fun main() = runBlocking {
274274

275275
</div>
276276

277-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt)
277+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt).
278278
279279
<!--- TEST
280280
I'm sleeping 0 ...
@@ -313,7 +313,7 @@ fun main() = runBlocking {
313313

314314
</div>
315315

316-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-06.kt)
316+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-06.kt).
317317
318318
It produces the following output:
319319

@@ -357,7 +357,7 @@ fun main() = runBlocking {
357357

358358
</div>
359359

360-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt)
360+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt).
361361
362362
There is no longer an exception when running this code:
363363

docs/channels.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fun main() = runBlocking {
7171

7272
</div>
7373

74-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt)
74+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt).
7575
7676
The output of this code is:
7777

@@ -118,7 +118,7 @@ fun main() = runBlocking {
118118

119119
</div>
120120

121-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt)
121+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt).
122122
123123
<!--- TEST
124124
1
@@ -160,7 +160,7 @@ fun main() = runBlocking {
160160

161161
</div>
162162

163-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt)
163+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt).
164164
165165
<!--- TEST
166166
1
@@ -231,7 +231,7 @@ fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = p
231231

232232
</div>
233233

234-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-04.kt)
234+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-04.kt).
235235
236236
<!--- TEST
237237
1
@@ -322,7 +322,7 @@ fun CoroutineScope.filter(numbers: ReceiveChannel<Int>, prime: Int) = produce<In
322322

323323
</div>
324324

325-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt)
325+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt).
326326
327327
The output of this code is:
328328

@@ -341,7 +341,7 @@ The output of this code is:
341341

342342
<!--- TEST -->
343343

344-
Note, that you can build the same pipeline using
344+
Note that you can build the same pipeline using
345345
[`iterator`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/iterator.html)
346346
coroutine builder from the standard library.
347347
Replace `produce` with `iterator`, `send` with `yield`, `receive` with `next`,
@@ -425,7 +425,7 @@ fun CoroutineScope.launchProcessor(id: Int, channel: ReceiveChannel<Int>) = laun
425425

426426
</div>
427427

428-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-06.kt)
428+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-06.kt).
429429
430430
The output will be similar to the the following one, albeit the processor ids that receive
431431
each specific integer may be different:
@@ -445,7 +445,7 @@ Processor #3 received 10
445445

446446
<!--- TEST lines.size == 10 && lines.withIndex().all { (i, line) -> line.startsWith("Processor #") && line.endsWith(" received ${i + 1}") } -->
447447

448-
Note, that cancelling a producer coroutine closes its channel, thus eventually terminating iteration
448+
Note that cancelling a producer coroutine closes its channel, thus eventually terminating iteration
449449
over the channel that processor coroutines are doing.
450450

451451
Also, pay attention to how we explicitly iterate over channel with `for` loop to perform fan-out in `launchProcessor` code.
@@ -505,7 +505,7 @@ suspend fun sendString(channel: SendChannel<String>, s: String, time: Long) {
505505

506506
</div>
507507

508-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt)
508+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt).
509509
510510
The output is:
511511

@@ -557,7 +557,7 @@ fun main() = runBlocking<Unit> {
557557

558558
</div>
559559

560-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt)
560+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt).
561561
562562
It prints "sending" _five_ times using a buffered channel with capacity of _four_:
563563

@@ -612,7 +612,7 @@ suspend fun player(name: String, table: Channel<Ball>) {
612612

613613
</div>
614614

615-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-09.kt)
615+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-09.kt).
616616
617617
The "ping" coroutine is started first, so it is the first one to receive the ball. Even though "ping"
618618
coroutine immediately starts receiving the ball again after sending it back to the table, the ball gets
@@ -627,7 +627,7 @@ pong Ball(hits=4)
627627

628628
<!--- TEST -->
629629

630-
Note, that sometimes channels may produce executions that look unfair due to the nature of the executor
630+
Note that sometimes channels may produce executions that look unfair due to the nature of the executor
631631
that is being used. See [this issue](https://github.com/Kotlin/kotlinx.coroutines/issues/111) for details.
632632

633633
### Ticker channels
@@ -675,7 +675,7 @@ fun main() = runBlocking<Unit> {
675675

676676
</div>
677677

678-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-10.kt)
678+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-channel-10.kt).
679679
680680
It prints following lines:
681681

0 commit comments

Comments
 (0)