-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathEventLoop.kt
31 lines (21 loc) · 1.03 KB
/
EventLoop.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@file:OptIn(ObsoleteWorkersApi::class)
package kotlinx.coroutines
import kotlin.coroutines.*
import kotlin.native.concurrent.*
import kotlin.time.*
internal actual abstract class EventLoopImplPlatform : EventLoop() {
private val current = Worker.current
protected actual fun unpark() {
current.executeAfter(0L, {})// send an empty task to unpark the waiting event loop
}
protected actual fun reschedule(now: Long, delayedTask: EventLoopImplBase.DelayedTask) {
DefaultExecutor.invokeOnTimeout(now, delayedTask, EmptyCoroutineContext)
}
}
internal class EventLoopImpl: EventLoopImplBase() {
override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle =
DefaultDelay.invokeOnTimeout(timeMillis, block, context)
}
internal actual fun createEventLoop(): EventLoop = EventLoopImpl()
private val startingPoint = TimeSource.Monotonic.markNow()
internal actual fun nanoTime(): Long = (TimeSource.Monotonic.markNow() - startingPoint).inWholeNanoseconds