Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental |
| 6 | |
| 7 | import kotlin.coroutines.experimental.* |
| 8 | |
| 9 | /** |
| 10 | * A coroutine dispatcher that is not confined to any specific thread. |
| 11 | * It executes initial continuation of the coroutine _right here_ in the current call-frame |
| 12 | * and let the coroutine resume in whatever thread that is used by the corresponding suspending function, without |
| 13 | * mandating any specific threading policy. |
| 14 | * |
| 15 | * Note, that if you need your coroutine to be confined to a particular thread or a thread-pool after resumption, |
| 16 | * but still want to execute it in the current call-frame until its first suspension, then you can use |
| 17 | * an optional [CoroutineStart] parameter in coroutine builders like [launch] and [async] setting it to the |
| 18 | * the value of [CoroutineStart.UNDISPATCHED]. |
| 19 | */ |
| 20 | public object Unconfined : CoroutineDispatcher() { |
| 21 | override fun isDispatchNeeded(context: CoroutineContext): Boolean = false |
| 22 | override fun dispatch(context: CoroutineContext, block: Runnable) { throw UnsupportedOperationException() } |
| 23 | override fun toString(): String = "Unconfined" |
| 24 | } |