concurrency - how to make this play scala controller work? -
i trying create controller extracts file on fly archive , then renders static asset default asset controller
import play.api.play.current // import controllers.assets import play.api.logger import myextract.extract import scala.concurrent.{executioncontext, future} import play.api.libs.concurrent.execution.implicits.defaultcontext object myassets extends controller { // drop version , serve asset def at(path: string, file: string): action[anycontent] = action.async { logger.info("looking file = %s" format file) val ret = future { extract.getfile(path, file) // extracts file archive // throws exception if file cannot extracted } ret.map { v => assets.at(path, file) } } }
i these errors @ compile
./activator compile [info] loading project definition /home/sylvain/yo-scala/project [info] set current project play-slick-advanced (in build file:/home /sylvain/yo-scala/) [info] compiling 1 scala source , 1 java source /home/sylvain/yo-scala/target/scala-2.11/classes... [error] /home/sylvain/yo-scala/app/controllers/myassets.scala:14: overloaded method value async alternatives: [error] (block: play.api.mvc.request[play.api.mvc.anycontent] => scala.concurrent.future[play.api.mvc.result])play.api.mvc.action[play.api.mvc.anycontent] <and> [error] (block: => scala.concurrent.future[play.api.mvc.result])play.api.mvc.action[play.api.mvc.anycontent] [error] cannot applied (scala.concurrent.future[play.api.mvc.action[play.api.mvc.anycontent]]) [error] def at(path: string, file: string): action[anycontent] = action.async { [error] [error] 1 error found [error] (compile:compile) compilation failed
you either have make sure action returns future
:
import play.api.play.current // import controllers.assets import play.api.logger import myextract.extract import scala.concurrent.{executioncontext, future} import play.api.libs.concurrent.execution.implicits.defaultcontext object myassets extends controller { // drop version , serve asset def at(path: string, file: string): action[anycontent] = action.async { logger.info("looking file = %s" format file) val ret = future { extract.getfile(path, file) // extracts file archive // throws exception if file cannot extracted } ret.map { v => scala.concurrent.future {assets.at(path, file)} } } }
or change it's not async
anymore:
import play.api.play.current // import controllers.assets import play.api.logger import myextract.extract import scala.concurrent.{executioncontext, future} import play.api.libs.concurrent.execution.implicits.defaultcontext object myassets extends controller { // drop version , serve asset def at(path: string, file: string): action[anycontent] = action { logger.info("looking file = %s" format file) val ret = future { extract.getfile(path, file) // extracts file archive // throws exception if file cannot extracted } ret.map { v => assets.at(path, file) } } }
Comments
Post a Comment