简体   繁体   English

Scala 将变量转换为未来?

[英]Scala Convert a Variable to Future?

I have a Case Class User and I want to return it as Future(User).我有一个案例 Class 用户,我想将其作为未来(用户)返回。 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?有人可以帮助我使用正确的语法将非未来结果转换为未来返回类型吗?

If you don't define an ExecutionContext elsewhere, you can use Scala's global ExecutionContext with either:如果您没有在其他地方定义ExecutionContext ,则可以将 Scala 的全局 ExecutionContext 与以下任何一种一起使用:

import scala.concurrent.ExecutionContext.Implicits.global

or:或者:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM