Make use of SAM instead.
This commit is contained in:
parent
07c5935ddb
commit
3ae618450f
3 changed files with 10 additions and 18 deletions
|
|
@ -15,7 +15,6 @@ package org.apache.pekko.pattern
|
|||
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.CompletionStage
|
||||
import java.util.function.BiConsumer
|
||||
|
||||
import scala.concurrent.{ ExecutionContext, Future, Promise }
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
|
@ -78,11 +77,9 @@ trait FutureTimeoutSupport {
|
|||
using.scheduleOnce(duration) {
|
||||
try {
|
||||
val future = value
|
||||
future.whenComplete(new BiConsumer[T, Throwable] {
|
||||
override def accept(t: T, ex: Throwable): Unit = {
|
||||
if (t != null) p.complete(t)
|
||||
if (ex != null) p.completeExceptionally(ex)
|
||||
}
|
||||
future.handle[Unit]((t: T, ex: Throwable) => {
|
||||
if (t != null) p.complete(t)
|
||||
if (ex != null) p.completeExceptionally(ex)
|
||||
})
|
||||
} catch {
|
||||
case NonFatal(ex) => p.completeExceptionally(ex)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
package org.apache.pekko.pattern
|
||||
|
||||
import java.util.concurrent.CompletionStage
|
||||
import java.util.function.BiConsumer
|
||||
|
||||
import scala.concurrent.{ ExecutionContext, Future }
|
||||
import scala.util.{ Failure, Success }
|
||||
|
|
@ -56,19 +55,15 @@ trait PipeToSupport {
|
|||
final class PipeableCompletionStage[T](val future: CompletionStage[T])(
|
||||
implicit @unused executionContext: ExecutionContext) {
|
||||
def pipeTo(recipient: ActorRef)(implicit sender: ActorRef = Actor.noSender): CompletionStage[T] = {
|
||||
future.whenComplete(new BiConsumer[T, Throwable] {
|
||||
override def accept(t: T, ex: Throwable): Unit = {
|
||||
if (t != null) recipient ! t
|
||||
if (ex != null) recipient ! Status.Failure(ex)
|
||||
}
|
||||
future.whenComplete((t: T, ex: Throwable) => {
|
||||
if (t != null) recipient ! t
|
||||
if (ex != null) recipient ! Status.Failure(ex)
|
||||
})
|
||||
}
|
||||
def pipeToSelection(recipient: ActorSelection)(implicit sender: ActorRef = Actor.noSender): CompletionStage[T] = {
|
||||
future.whenComplete(new BiConsumer[T, Throwable] {
|
||||
override def accept(t: T, ex: Throwable): Unit = {
|
||||
if (t != null) recipient ! t
|
||||
if (ex != null) recipient ! Status.Failure(ex)
|
||||
}
|
||||
future.whenComplete((t: T, ex: Throwable) => {
|
||||
if (t != null) recipient ! t
|
||||
if (ex != null) recipient ! Status.Failure(ex)
|
||||
})
|
||||
}
|
||||
def to(recipient: ActorRef): PipeableCompletionStage[T] = to(recipient, Actor.noSender)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue