@@ -22,10 +22,10 @@ import kotlin.jvm.*
22
22
* This is a **delicate** API. The result of this method is a closeable resource with the
23
23
* associated native resources (threads or native workers). It should not be allocated in place,
24
24
* should be closed at the end of its lifecycle, and has non-trivial memory and CPU footprint.
25
- * If you do not need a separate thread- pool, but only have to limit effective parallelism of the dispatcher,
25
+ * If you do not need a separate thread pool, but only have to limit effective parallelism of the dispatcher,
26
26
* it is recommended to use [CoroutineDispatcher.limitedParallelism] instead.
27
27
*
28
- * If you need a completely separate thread- pool with scheduling policy that is based on the standard
28
+ * If you need a completely separate thread pool with scheduling policy that is based on the standard
29
29
* JDK executors, use the following expression:
30
30
* `Executors.newSingleThreadExecutor().asCoroutineDispatcher()`.
31
31
* See `Executor.asCoroutineDispatcher` for details.
@@ -37,5 +37,30 @@ import kotlin.jvm.*
37
37
public fun newSingleThreadContext (name : String ): CloseableCoroutineDispatcher =
38
38
newFixedThreadPoolContext(1 , name)
39
39
40
+ /* *
41
+ * Creates a coroutine execution context with the fixed-size thread-pool and built-in [yield] support.
42
+ * **NOTE: The resulting [CoroutineDispatcher] owns native resources (its threads).
43
+ * Resources are reclaimed by [CloseableCoroutineDispatcher.close].**
44
+ *
45
+ * If the resulting dispatcher is [closed][CloseableCoroutineDispatcher.close] and
46
+ * attempt to submit a continuation task is made,
47
+ * * On the JVM, the [Job] of the affected task is [cancelled][Job.cancel] and the task is submitted to the
48
+ * [Dispatchers.IO], so that the affected coroutine can clean up its resources and promptly complete.
49
+ * * On Native, the attempt to submit a task throws an exception.
50
+ *
51
+ * This is a **delicate** API. The result of this method is a closeable resource with the
52
+ * associated native resources (threads or native workers). It should not be allocated in place,
53
+ * should be closed at the end of its lifecycle, and has non-trivial memory and CPU footprint.
54
+ * If you do not need a separate thread pool, but only have to limit effective parallelism of the dispatcher,
55
+ * it is recommended to use [CoroutineDispatcher.limitedParallelism] instead.
56
+ *
57
+ * If you need a completely separate thread pool with scheduling policy that is based on the standard
58
+ * JDK executors, use the following expression:
59
+ * `Executors.newFixedThreadPool().asCoroutineDispatcher()`.
60
+ * See `Executor.asCoroutineDispatcher` for details.
61
+ *
62
+ * @param nThreads the number of threads.
63
+ * @param name the base name of the created threads.
64
+ */
40
65
@ExperimentalCoroutinesApi
41
66
public expect fun newFixedThreadPoolContext (nThreads : Int , name : String ): CloseableCoroutineDispatcher
0 commit comments