package eu.xeppaka.scalalearn

import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import eu.xeppaka.scalalearn.Actor2.{Request, Response, SendResponse}

import scala.concurrent.duration._

object Actor2 {
  case object Request
  case object Response
  private case class SendResponse(destination: ActorRef)

  def props(): Props = Props(new Actor2())
}

class Actor2 extends Actor with ActorLogging {
  import context.dispatcher

  override def receive: Receive = {
    case Request =>
      log.info("actor2 request")
      context.system.scheduler.scheduleOnce(10.millis, self, SendResponse(sender()))
    case SendResponse(destination) =>
      destination ! Response
  }
}
