title: withTimeout function gives IllegalStateException: There is no event loop. Use runBlocking { ... } to start one. in Kotlin Multiplatform iOS client
body: <p>Update:
  It works if I first execute a coroutine without timeout and then withTimeout. But If I execute a coroutine withTimeout first then it gives me an error. same goes for Async as well.</p>
  
  <p>I am creating a demo kotlin multiplatform application where I am executing an API call with ktor.
  I want to have a configurable timeout function on ktor request so I am using withTimeout at coroutine level.</p>
  
  <p>Here is my function call with network API.</p>
  
  <pre><code>suspend fun &lt;T&gt; onNetworkWithTimeOut(
      url: String,
      timeoutInMillis: Long,
      block: suspend CoroutineScope.() -&gt; Any): T {
      return withTimeout(timeoutInMillis) {
          withContext(dispatchers.io, block)
      } as T
  }
  
  suspend fun &lt;T&gt; onNetworkWithoutTimeOut(url: String, block: suspend CoroutineScope.() -&gt; Any): T {
      return withContext(dispatchers.io, block) as T
  }
  </code></pre>
  
  <p>Here is my AppDispatcher class for the iOSMain module.</p>
  
  <pre><code>@InternalCoroutinesApi
  actual class AppDispatchersImpl : AppDispatchers {
  @SharedImmutable
  override val main: CoroutineDispatcher =
      NsQueueDispatcher(dispatch_get_main_queue())
  
  @SharedImmutable
  override val io: CoroutineDispatcher =
      NsQueueDispatcher(dispatch_get_main_queue())
  
  internal class NsQueueDispatcher(
      @SharedImmutable private val dispatchQueue: dispatch_queue_t
  ) : CoroutineDispatcher() {
      override fun dispatch(context: CoroutineContext, block: Runnable) {
          NSRunLoop.mainRunLoop().performBlock {
              block.run()
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>so the function with the timeout gives me the following error in iOS client.</p>
  
  <pre><code>kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
  </code></pre>
  
  <p>I am using 1.3.2-native-mt-1 version of the kotlin-coroutine-native.
  I have created a sample demo application at the following URL.
  <a href="https://github.com/dudhatparesh/kotlin-multiplat-platform-example" rel="noreferrer">https://github.com/dudhatparesh/kotlin-multiplat-platform-example</a></p>