Search code examples
javascalaakkaactor

Actor design for queue with a long running task


I have a bunch of actors running which need to enqueue tasks to be processed sequentially, one at a time. I will need an actor to process the tasks on the queue. Is it ok to create one actor and pass a reference to that actor as a parameter to each job (an implicit queue)? Ex.

Actor:

class QActor extends Actor{
  def receive = {
    case input => sender ! doSomething(input)
  }
}

Sender

val future = myQActor ? msg
Await.result(future)

Solution

  • Using another actor and its mailbox as a queue is fine, just don't block in the sender.