EventLoop

fun EventLoop(
    thread: Thread = Thread.currentThread(),
    parentJob: Job? = null
): CoroutineDispatcher
(source)

Platform and version requirements: JVM

Creates a new event loop that is bound the specified thread (current thread by default) and stops accepting new events when parentJob completes. Every continuation that is scheduled onto this event loop unparks the specified thread via LockSupport.unpark.

The main event-processing loop using the resulting eventLoop object should look like this:

while (needsToBeRunning) {
    if (Thread.interrupted()) break // or handle somehow
    LockSupport.parkNanos(eventLoop.processNextEvent()) // event loop will unpark
}