The primary reason why this method is missing is that it does not really have good semantics: the static type Future[Either[Throwable, T]]
does not ensure that that future cannot fail, hence the type change does not gain you much in general.
It can of course make sense if you control all the code which handles those futures, and in that case it is trivial to add it yourself (the name is due to me posting before first coffee, feel free to replace with something better):
implicit class FutureOps[T](val f: Future[T]) extends AnyVal {
def lift(implicit ec: ExecutionContext): Future[Either[Throwable,T]] = {
val p = promise[Either[Throwable,T]]()
f.onComplete {
case Success(s) => p success Right(s)
case Failure(ex) => p success Left(ex)
}
p.future
}
}
It works very similarly with Akka 2.0 futures, hence I leave that exercise to the reader.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…