Home > Software design >  Scala Convert a Variable to Future?
Scala Convert a Variable to Future?

Time:09-28

I have a case class User and I want to return it as Future[User]. But when I do the same I get this error:

No implicits found for parameter executor: ExecutionContext

Can someone help me with the right syntax to convert a non future result to future return type?

CodePudding user response:

If you don't define an ExecutionContext elsewhere, you can use Scala's global ExecutionContext with either:

import scala.concurrent.ExecutionContext.Implicits.global

or:

implicit val ec: scala.concurrent.ExecutionContext = 
  scala.concurrent.ExecutionContext.global
  • Related