我们目前有这样的代码
def somemethod() : Future[Resp] = {
val responseFuture = service.serveV2(req)
val nextFuture = responseFuture flatMap {
//do something on success including call to next async service
}
nextFuture
}
当然,地图会在超时时被跳过,但我需要将该超时转换为适当的异常,我可以将其传递给我们的 Web 框架以返回正确的响应代码。在scala中如何做到这一点?
另外值得注意的是,我需要返回那个未来。也许我应该在 responseFuture.onFailure 中创建一个承诺并将其连接到该承诺中,还是我完全不在这里?(我想知道是否有更简单的方法,或者我可以尝试走这条路)。