Skip to content

Commit

Permalink
Optimize match case using single abstract method
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushhooda committed May 26, 2019
1 parent e727ce7 commit 5b27ef3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions core/src/main/scala/org/http4s/internal/package.scala
@@ -1,7 +1,6 @@
package org.http4s

import java.util.concurrent.{CancellationException, CompletableFuture, CompletionException}
import java.util.function.BiFunction

import cats.effect.{Async, Concurrent, ConcurrentEffect, Effect, IO}
import cats.implicits._
Expand Down Expand Up @@ -126,13 +125,11 @@ package object internal {
implicit F: Concurrent[F]): F[A] =
fcf.flatMap { cf =>
F.cancelable(cb => {
cf.handle[Unit](new BiFunction[A, Throwable, Unit] {
override def apply(result: A, err: Throwable): Unit = err match {
case null => cb(Right(result))
case _: CancellationException => ()
case ex: CompletionException if ex.getCause ne null => cb(Left(ex.getCause))
case ex => cb(Left(ex))
}
cf.handle[Unit]((result: A, err: Throwable) => err match {
case null => cb(Right(result))
case _: CancellationException => ()
case ex: CompletionException if ex.getCause ne null => cb(Left(ex.getCause))
case ex => cb(Left(ex))
})
F.delay { cf.cancel(true); () }
})
Expand Down

0 comments on commit 5b27ef3

Please sign in to comment.