Skip to content

Instantly share code, notes, and snippets.

@jchampemont
Created March 3, 2016 08:05
Show Gist options
  • Save jchampemont/6d7e5cacb564b546322e to your computer and use it in GitHub Desktop.
Save jchampemont/6d7e5cacb564b546322e to your computer and use it in GitHub Desktop.
A simple akka actor that procrastinates (i.e. send a message to an actor in a specified duration)
import akka.actor.{Actor, ActorRef}
import scala.concurrent.duration._
case class Procrastinate[M](duration: FiniteDuration, actor: ActorRef, message: M)
class Procrastinactor extends Actor {
import scala.concurrent.ExecutionContext.Implicits.global
def receive = {
case Procrastinate(duration, actor, message) => {
if(duration > 0.millis)
context.system.scheduler.scheduleOnce(duration, actor, message)
else
actor ! message
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment