I've a Future[List[Person]]
[1] 我想要得到List[Person]
从中。我该怎么做 ?
import scala.concurrent.Future
val futPersons : Future[List[Person]] = ....
有多种方式:
futPersons.map { personList =>
....
}
该地图返回另一个Future
由您从地图返回的任何内容组成。仅当 future 成功完成时,映射才会执行。如果需要处理失败,可以使用 onComplete
futPersons.onComplete {
case Success(personList) => ...
case Failure(exception) => ...
}
或者你可以等待未来完成(这是阻塞的):
val personList: List[Person] = Await.result(futPersons, 1 minutes)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)