Skip to content

Commit 240b7da

Browse files
committed
~ Doc for newSingleThreadContext/newFixedThreadPoolContext
1 parent 6ed0fe2 commit 240b7da

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ public abstract class ExecutorCoroutineDispatcher: CoroutineDispatcher(), Closea
3939
/**
4040
* Converts an instance of [ExecutorService] to an implementation of [ExecutorCoroutineDispatcher].
4141
*
42-
* Note, that if the underlying executor throws [RejectedExecutionException] on
43-
* attempt to submit a continuation task (it typically happens on executor shutdown or when it uses limited queues),
42+
* If the underlying executor throws [RejectedExecutionException] on
43+
* attempt to submit a continuation task (it happens when [closing][ExecutorCoroutineDispatcher.close] the
44+
* resulting dispatcher, on underlying executor [shutdown][ExecutorService.shutdown], or when it uses limited queues),
4445
* then the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
4546
* [Dispatchers.IO], so that the affected coroutine can cleanup its resources and promptly complete.
4647
*/
@@ -51,8 +52,9 @@ public fun ExecutorService.asCoroutineDispatcher(): ExecutorCoroutineDispatcher
5152
/**
5253
* Converts an instance of [Executor] to an implementation of [CoroutineDispatcher].
5354
*
54-
* Note, that if the underlying executor throws [RejectedExecutionException] on
55-
* attempt to submit a continuation task (it typically happens on executor shutdown or when it uses limited queues),
55+
* If the underlying executor throws [RejectedExecutionException] on
56+
* attempt to submit a continuation task (it happens when [closing][ExecutorCoroutineDispatcher.close] the
57+
* resulting dispatcher, on underlying executor [shutdown][ExecutorService.shutdown], or when it uses limited queues),
5658
* then the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
5759
* [Dispatchers.IO], so that the affected coroutine can cleanup its resources and promptly complete.
5860
*/

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

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import kotlin.coroutines.*
1414
* **NOTE: The resulting [ExecutorCoroutineDispatcher] owns native resources (its thread).
1515
* Resources are reclaimed by [ExecutorCoroutineDispatcher.close].**
1616
*
17+
* If the resulting dispatcher is [closed][ExecutorCoroutineDispatcher.close] and
18+
* attempt to submit a continuation task is made,
19+
* then the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
20+
* [Dispatchers.IO], so that the affected coroutine can cleanup its resources and promptly complete.
21+
*
1722
* **NOTE: This API will be replaced in the future**. A different API to create thread-limited thread pools
1823
* that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
1924
* will be provided, thus avoiding potential thread leaks and also significantly improving performance, due
@@ -35,6 +40,11 @@ public fun newSingleThreadContext(name: String): ExecutorCoroutineDispatcher =
3540
* **NOTE: The resulting [ExecutorCoroutineDispatcher] owns native resources (its threads).
3641
* Resources are reclaimed by [ExecutorCoroutineDispatcher.close].**
3742
*
43+
* If the resulting dispatcher is [closed][ExecutorCoroutineDispatcher.close] and
44+
* attempt to submit a continuation task is made,
45+
* then the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
46+
* [Dispatchers.IO], so that the affected coroutine can cleanup its resources and promptly complete.
47+
*
3848
* **NOTE: This API will be replaced in the future**. A different API to create thread-limited thread pools
3949
* that is based on a shared thread-pool and does not require the resulting dispatcher to be explicitly closed
4050
* will be provided, thus avoiding potential thread leaks and also significantly improving performance, due

0 commit comments

Comments
 (0)