Actor + playframework + slick query


(PSY) #1

I am new to akka + playframework. I have been using direct slick run method in play async action method. run(. … ) method returns Future[T]. Now my question is - will it be okay to use actor ask method within the play async action in controller to execute slick run method?

package controllers

import{ActorRef, ActorSystem, Props}
import akka.pattern.ask
import akka.util.Timeout
import javax.inject.{Inject, Singleton}
import play.api.mvc._
import services.actorServices.TestActor

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

class ActorTestController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit assetsFinder: AssetsFinder, executionContext: ExecutionContext)
  extends AbstractController(cc) {

  val testActor: ActorRef = actorSystem.actorOf(Props[TestActor])
  implicit val timeout: Timeout = Timeout.apply(2 second)

  def test: Action[AnyContent] =Action.async{
    (testActor ? "test").mapTo[String].map(string => Ok(string))


package services.actorServices

import services.dbServices.HomePageDAO


class TestActor extends Actor {

  override def receive: Receive = {
    case "test" => { seqOfString =>
        sender() ! seqOfString.head


Actually ask does not work with a method which compute in Future :(