use CompletableFuture#failedStage (#2013)

This commit is contained in:
PJ Fanning 2025-08-06 03:44:43 +01:00 committed by GitHub
parent 1b8de23911
commit 7d5e5daa70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -137,6 +137,7 @@ object Futures {
/**
* Creates an already completed CompletionStage with the specified exception
*/
@deprecated("Use `CompletableFuture#failedStage` instead.", since = "2.0.0")
def failedCompletionStage[T](ex: Throwable): CompletionStage[T] = {
val f = CompletableFuture.completedFuture[T](null.asInstanceOf[T])
f.obtrudeException(ex)

View file

@ -21,7 +21,6 @@ import scala.util.control.NonFatal
import org.apache.pekko
import pekko.actor._
import pekko.dispatch.Futures
trait FutureTimeoutSupport {
@ -70,7 +69,7 @@ trait FutureTimeoutSupport {
implicit ec: ExecutionContext): CompletionStage[T] =
if (duration.isFinite && duration.length < 1) {
try value
catch { case NonFatal(t) => Futures.failedCompletionStage(t) }
catch { case NonFatal(t) => CompletableFuture.failedStage(t) }
} else {
val p = new CompletableFuture[T]
using.scheduleOnce(duration) {
@ -129,7 +128,7 @@ trait FutureTimeoutSupport {
val stage: CompletionStage[T] =
try value
catch {
case NonFatal(t) => Futures.failedCompletionStage(t)
case NonFatal(t) => CompletableFuture.failedStage(t)
}
if (stage.toCompletableFuture.isDone) {
stage