我正在尝试使用Future从一个巧妙的动作返回的 s 将一些基本功能链接在一起,我遇到了一些非常微不足道的绊脚石。
andThen和onSuccess方法都需要作为PartialFunction参数传递。我的理解可能有很大的缺陷,但在阅读了匿名函数之后,似乎andThen需要知道你的匿名函数以迎合任何Success或Failure输入。
鉴于onSuccess已经只满足这种Success情况,为什么它仍然需要是一个PartialFunction?
这段代码表明我遇到的问题:
val db = Database.forConfig("h2mem1")
try {
val f = db.run(setupCommands)
.onSuccess { println(_) }
Await.ready(f, 10.seconds )
}
finally db.close
我得到一个编译错误:
[error] found : Unit => Unit
[error] required: PartialFunction[Unit,?]
[error] .onSuccess { println(_) }