在下面的代码段中,Scala的未来[选项[T]]联合国包装
trait MyType1; trait MyType2
import scala.concurrent.Promise
val p1 = Promise[Option[MyType1]]()
val p2 = Promise[MyType2]()
我通过在p1和p2到另一个函数,其中我使用一个成功的未来完成的前景。呼叫此功能后,我尝试读取Promise中的值:
trait Test {
// get the Future from the promise
val f1 = p1.future
val f2 = p2.future
for {
someF1Elem <- f1
f1Elem <- someF1Elem
f2Elem <- f1Elem
} yield {
// do something with f1Elem and f2Elem
"..."
}
}
当我尝试编译此问题时,出现一些编译器问题。
Error:(52, 19) type mismatch;
found : Option[Nothing]
required: scala.concurrent.Future[?]
flElem <- someF1Elem
^
IntelliJ显示没有错误或者什么都没有,并且类型看起来是一致的。但我不确定编译器为什么不快乐!任何线索?