File tree Expand file tree Collapse file tree 4 files changed +13
-4
lines changed
main/kotlin/kotlinx/coroutines/experimental
test/kotlin/kotlinx/coroutines/experimental Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ Coroutine dispatchers implementing [CoroutineDispatcher]:
19
19
| [ CommonPool] | Confines coroutine execution to a shared pool of threads
20
20
| [ newSingleThreadContext] | Create new single-threaded coroutine context
21
21
| [ newFixedThreadPoolContext] | Creates new thread pool of a fixed size
22
- | [ Executor.toCoroutineDispatcher ] [ java.util.concurrent.Executor.toCoroutineDispatcher ] | Extension to convert any executor
22
+ | [ Executor.asCoroutineDispatcher ] [ java.util.concurrent.Executor.asCoroutineDispatcher ] | Extension to convert any executor
23
23
| [ Unconfined] | Does not confine coroutine execution in any way
24
24
25
25
Synchronization primitives for coroutines:
@@ -86,7 +86,7 @@ Select expression to perform multiple suspending operations simultaneously until
86
86
[ CommonPool ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-common-pool/index.html
87
87
[ newSingleThreadContext ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/new-single-thread-context.html
88
88
[ newFixedThreadPoolContext ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/new-fixed-thread-pool-context.html
89
- [ java.util.concurrent.Executor.toCoroutineDispatcher ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/java.util.concurrent.-executor/to -coroutine-dispatcher.html
89
+ [ java.util.concurrent.Executor.asCoroutineDispatcher ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/java.util.concurrent.-executor/as -coroutine-dispatcher.html
90
90
[ Unconfined ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-unconfined/index.html
91
91
[ delay ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/delay.html
92
92
[ yield ] : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/yield.html
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ import kotlin.coroutines.experimental.CoroutineContext
34
34
* a common pool of shared background threads.
35
35
* This is an appropriate choice for compute-intensive coroutines that consume a lot of CPU resources.
36
36
* * Private thread pools can be created with [newSingleThreadContext] and [newFixedThreadPoolContext].
37
- * * An arbitrary [Executor][java.util.concurrent.Executor] can be converted to dispatcher with [toCoroutineDispatcher ] extension function.
37
+ * * An arbitrary [Executor][java.util.concurrent.Executor] can be converted to dispatcher with [asCoroutineDispatcher ] extension function.
38
38
*
39
39
* This class ensures that debugging facilities in [newCoroutineContext] function work properly.
40
40
*/
Original file line number Diff line number Diff line change @@ -24,10 +24,19 @@ import kotlin.coroutines.experimental.CoroutineContext
24
24
25
25
/* *
26
26
* Converts an instance of [Executor] to an implementation of [CoroutineDispatcher].
27
+ * @suppress **Deprecated**: Renamed to [asCoroutineDispatcher].
27
28
*/
29
+ @Deprecated(" Renamed to `asCoroutineDispatcher`" ,
30
+ replaceWith = ReplaceWith (" asCoroutineDispatcher()" ))
28
31
public fun Executor.toCoroutineDispatcher (): CoroutineDispatcher =
29
32
ExecutorCoroutineDispatcher (this )
30
33
34
+ /* *
35
+ * Converts an instance of [Executor] to an implementation of [CoroutineDispatcher].
36
+ */
37
+ public fun Executor.asCoroutineDispatcher (): CoroutineDispatcher =
38
+ ExecutorCoroutineDispatcher (this )
39
+
31
40
internal open class ExecutorCoroutineDispatcher (
32
41
private val executor : Executor
33
42
) : CoroutineDispatcher(), Delay {
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ class ExecutorsTest {
78
78
@Test
79
79
fun testToExecutor () {
80
80
val executor = Executors .newSingleThreadExecutor { r -> Thread (r, " TestExecutor" ) }
81
- runBlocking(executor.toCoroutineDispatcher ()) {
81
+ runBlocking(executor.asCoroutineDispatcher ()) {
82
82
checkThreadName(" TestExecutor" )
83
83
}
84
84
executor.shutdown()
You can’t perform that action at this time.
0 commit comments