你打电话的时候
Await.result(myFuture, DURATION)
在播放应用程序内部,当持续时间到期时,幕后会发生什么?
netty是否会在/返回时忽略响应?
更差.Await.result
超时时抛出异常,Future
仍然会执行.它与Play或netty无关.工作由后台的执行上下文完成,您无法回调.这不是需要处理的网络Future
,而是你.所以从某种意义上说,你可以说结果被忽略了,因为现在已经抛出了异常代替它.
您可以在REPL中尝试:
import scala.concurrent._ import scala.concurrent.duration._ import scala.concurrent.ExecutionContext.Implicits.global scala> def longFuture = Future { Thread.sleep(10000); println("Finally done..") } scala> Await.result(longFuture, Duration("1 second")) java.util.concurrent.TimeoutException: Futures timed out after [1 second] at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219) at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223) at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:190) at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53) at scala.concurrent.Await$.result(package.scala:190) ... 33 elided // 10 seconds later.. scala> Finally done..