Created
March 3, 2016 08:05
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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