1 /* 2 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.internal 6 7 import kotlinx.coroutines.* 8 9 /** @suppress */ 10 @InternalCoroutinesApi // Emulating DI for Kotlin object's 11 public interface MainDispatcherFactory { 12 public val loadPriority: Int // higher priority wins 13 14 /** 15 * Creates the main dispatcher. [allFactories] parameter contains all factories found by service loader. 16 * This method is not guaranteed to be idempotent. 17 * 18 * It is required that this method fails with an exception instead of returning an instance that doesn't work 19 * correctly as a [Delay]. 20 * The reason for this is that, on the JVM, [DefaultDelay] will use [Dispatchers.Main] for most delays by default 21 * if this method returns an instance without throwing. 22 */ createDispatchernull23 public fun createDispatcher(allFactories: List<MainDispatcherFactory>): MainCoroutineDispatcher 24 25 /** 26 * Hint used along with error message when the factory failed to create a dispatcher. 27 */ 28 public fun hintOnError(): String? = null 29 } 30