Skip to content

Commit

Permalink
Use designated Scala methods for converter utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Jan 1, 2024
1 parent 8a009e0 commit 4f80b1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private[http] object RoutingJavaMapping {
// val javaToScalaResponseEntity extends Inherited[javadsl.model.ResponseEntity, scaladsl.model.ResponseEntity]

implicit final class ConvertCompletionStage[T](val stage: CompletionStage[T]) extends AnyVal {
import pekko.util.FutureConverters
def asScala = FutureConverters.asScala(stage)
import pekko.util.FutureConverters._
def asScala = CompletionStageOps(stage).asScala
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import java.util.function.Predicate
import pekko.dispatch.ExecutionContexts
import pekko.event.LoggingAdapter
import pekko.http.javadsl.server
import pekko.util.FutureConverters
import pekko.util.FutureConverters._

import scala.concurrent.duration.FiniteDuration
Expand Down Expand Up @@ -98,8 +97,8 @@ abstract class BasicDirectives {
def mapRouteResultFuture(f: JFunction[CompletionStage[RouteResult], CompletionStage[RouteResult]],
inner: Supplier[Route]): Route = RouteAdapter {
D.mapRouteResultFuture(stage =>
FutureConverters.asScala(
f(stage.fast.map(_.asJava)(ExecutionContexts.parasitic).asJava)).fast.map(_.asScala)(
CompletionStageOps(
f(stage.fast.map(_.asJava)(ExecutionContexts.parasitic).asJava)).asScala.fast.map(_.asScala)(
ExecutionContexts.parasitic)) {
inner.get.delegate
}
Expand All @@ -108,15 +107,15 @@ abstract class BasicDirectives {
def mapRouteResultWith(f: JFunction[RouteResult, CompletionStage[RouteResult]], inner: Supplier[Route]): Route =
RouteAdapter {
D.mapRouteResultWith(r =>
FutureConverters.asScala(f(r.asJava)).fast.map(_.asScala)(ExecutionContexts.parasitic)) {
CompletionStageOps(f(r.asJava)).asScala.fast.map(_.asScala)(ExecutionContexts.parasitic)) {
inner.get.delegate
}
}

def mapRouteResultWithPF(
f: PartialFunction[RouteResult, CompletionStage[RouteResult]], inner: Supplier[Route]): Route = RouteAdapter {
D.mapRouteResultWith(r =>
FutureConverters.asScala(f(r.asJava)).fast.map(_.asScala)(ExecutionContexts.parasitic)) {
CompletionStageOps(f(r.asJava)).asScala.fast.map(_.asScala)(ExecutionContexts.parasitic)) {
inner.get.delegate
}
}
Expand Down Expand Up @@ -174,7 +173,7 @@ abstract class BasicDirectives {
def recoverRejectionsWith(
f: JFunction[JIterable[Rejection], CompletionStage[RouteResult]], inner: Supplier[Route]): Route = RouteAdapter {
D.recoverRejectionsWith(rs =>
FutureConverters.asScala(f.apply(Util.javaArrayList(rs.map(_.asJava)))).fast.map(_.asScala)(
CompletionStageOps(f.apply(Util.javaArrayList(rs.map(_.asJava)))).asScala.fast.map(_.asScala)(
ExecutionContexts.parasitic)) { inner.get.delegate }
}

Expand Down

0 comments on commit 4f80b1e

Please sign in to comment.