将隐式参数传递给Future.recover



我想将一个隐式参数传递给用于recoverFuture s的偏函数。

def delete(id: Long) = ... { implicit something =>
  serviceLayer.doSomething(id).recover(errorHandler)
}
def errorHandler: PartialFunction[Throwable, Result] = {
    // I want to access the implicit parameter here
    case e@SomeException(message) => ... and here
    case _ => ... and here
}

然后errorHandler需要接收something作为隐式参数:

def delete(id: Long) = ... { implicit something =>
  serviceLayer.doSomething(id).recover(errorHandler)
}
def errorHandler(implicit something: Something): PartialFunction[Throwable, Result] = {
    // Access something here
    case e@SomeException(message) => ... and here
    case _ => ... and here
}

相关内容

  • 没有找到相关文章

最新更新