@@ -11,24 +11,16 @@ import kotlin.native.concurrent.*
11
11
12
12
internal actual object DefaultExecutor : CoroutineDispatcher(), Delay {
13
13
14
- private val worker = Worker .start (name = " Dispatchers.Default" )
14
+ private val delegate = SingleThreadDispatcherImpl (name = " Dispatchers.Default" )
15
15
16
16
override fun dispatch (context : CoroutineContext , block : Runnable ) =
17
- worker.executeAfter( 0L ) { block. run () }
17
+ delegate.dispatch(context, block)
18
18
19
- override fun scheduleResumeAfterDelay (timeMillis : Long , continuation : CancellableContinuation <Unit >) {
20
- // TODO proper toMicros
21
- worker.executeAfter(timeMillis * 1000 )
22
- { with (continuation) { resumeUndispatched(Unit ) } }
23
- }
19
+ override fun scheduleResumeAfterDelay (timeMillis : Long , continuation : CancellableContinuation <Unit >) = delegate.scheduleResumeAfterDelay(timeMillis, continuation)
24
20
25
- override fun invokeOnTimeout (timeMillis : Long , block : Runnable , context : CoroutineContext ): DisposableHandle {
26
- // No API to cancel on timeout
27
- worker.executeAfter(timeMillis * 1000 ) { block.run () }
28
- return NonDisposableHandle
29
- }
21
+ override fun invokeOnTimeout (timeMillis : Long , block : Runnable , context : CoroutineContext ): DisposableHandle = delegate.invokeOnTimeout(timeMillis, block, context)
30
22
31
- actual fun enqueue (task : Runnable ): Unit = worker.executeAfter( 0L ) { task. run () }
23
+ actual fun enqueue (task : Runnable ): Unit = delegate.dispatch( EmptyCoroutineContext , task)
32
24
}
33
25
34
26
internal fun loopWasShutDown (): Nothing = error(" Cannot execute task because event loop was shut down" )
0 commit comments