Skip to content

Commit 28271c4

Browse files
authored
Reduce the number of coroutines in the runnable example (#3631)
Fixes KT-51515
1 parent c686eeb commit 28271c4

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
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 {

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)