com.convergencelabs.convergence.server.util.EventLoop.scala Maven / Gradle / Ivy
/*
* Copyright (c) 2019 - Convergence Labs, Inc.
*
* This file is part of the Convergence Server, which is released under
* the terms of the GNU General Public License version 3 (GPLv3). A copy
* of the GPLv3 should have been provided along with this file, typically
* located in the "LICENSE" file, which is part of this source code package.
* Alternatively, see for the
* full text of the GPLv3 license, if it was not provided.
*/
package com.convergencelabs.convergence.server.util
import akka.actor.typed.ActorRef
import com.convergencelabs.convergence.server.util.ActorBackedEventLoop.TaskScheduled
trait EventLoop {
def schedule(task: => Unit): Unit
}
object ActorBackedEventLoop {
case class TaskScheduled(task: () => Unit)
}
final class ActorBackedEventLoop(actor: ActorRef[TaskScheduled]) extends EventLoop {
import ActorBackedEventLoop._
def schedule(task: => Unit): Unit = {
actor ! TaskScheduled(() => task)
}
}