blob: 7314d6dd7110c5758f7afce55352a0149f95b709 [file] [log] [blame]
Roman Elizarovaa461cf2018-04-11 13:20:29 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovaa461cf2018-04-11 13:20:29 +03003 */
4
5package kotlinx.coroutines.experimental
6
7import 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 */
20public 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}