@@ -22,10 +22,10 @@ import kotlin.jvm.*
2222 * This is a **delicate** API. The result of this method is a closeable resource with the
2323 * associated native resources (threads or native workers). It should not be allocated in place,
2424 * 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,
2626 * it is recommended to use [CoroutineDispatcher.limitedParallelism] instead.
2727 *
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
2929 * JDK executors, use the following expression:
3030 * `Executors.newSingleThreadExecutor().asCoroutineDispatcher()`.
3131 * See `Executor.asCoroutineDispatcher` for details.
@@ -37,5 +37,30 @@ import kotlin.jvm.*
3737public fun newSingleThreadContext (name : String ): CloseableCoroutineDispatcher =
3838 newFixedThreadPoolContext(1 , name)
3939
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+ */
4065@ExperimentalCoroutinesApi
4166public expect fun newFixedThreadPoolContext (nThreads : Int , name : String ): CloseableCoroutineDispatcher
0 commit comments