Skip to content

Commit

Permalink
Remove fail fast future
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Nov 14, 2017
1 parent 0e752e3 commit 2ca66c9
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 101 deletions.
35 changes: 0 additions & 35 deletions core/src/main/scala/cats/data/FailFastFuture.scala

This file was deleted.

14 changes: 0 additions & 14 deletions core/src/main/scala/cats/instances/parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cats.kernel.Semigroup
import cats.syntax.either._
import cats.{Applicative, Apply, FlatMap, Functor, Monad, NonEmptyParallel, Parallel, ~>}

import scala.concurrent.{ExecutionContext, Future}

trait ParallelInstances extends ParallelInstances1 {
implicit def catsParallelForEitherValidated[E: Semigroup]: Parallel[Either[E, ?], Validated[E, ?]] = new Parallel[Either[E, ?], Validated[E, ?]] {
Expand Down Expand Up @@ -77,19 +76,6 @@ trait ParallelInstances extends ParallelInstances1 {
λ[Stream ~> ZipStream](v => new ZipStream(v))
}

implicit def catsStdParallelForFailFastFuture[A](implicit ec: ExecutionContext): Parallel[Future, FailFastFuture] =
new Parallel[Future, FailFastFuture] {

def monad: Monad[Future] = cats.instances.future.catsStdInstancesForFuture
def applicative: Applicative[FailFastFuture] = FailFastFuture.catsDataApplicativeForFailFastFuture

def sequential: FailFastFuture ~> Future =
λ[FailFastFuture ~> Future](_.value)

def parallel: Future ~> FailFastFuture =
λ[Future ~> FailFastFuture](f => FailFastFuture(f))
}


implicit def catsParallelForEitherTNestedParallelValidated[F[_], M[_], E: Semigroup]
(implicit P: Parallel[M, F]): Parallel[EitherT[M, E, ?], Nested[F, Validated[E, ?], ?]] =
Expand Down
8 changes: 0 additions & 8 deletions js/src/test/scala/cats/tests/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats
package js
package tests

import cats.data.FailFastFuture
import cats.kernel.laws.discipline.{MonoidTests => MonoidLawTests, SemigroupTests => SemigroupLawTests}
import cats.laws.discipline._
import cats.js.instances.Await
Expand Down Expand Up @@ -38,12 +37,6 @@ class FutureTests extends CatsSuite {
}
}

implicit def eqffa[A: Eq]: Eq[FailFastFuture[A]] =
Eq.by(_.value)


implicit def failFastArbitrary[A: Arbitrary]: Arbitrary[FailFastFuture[A]] =
Arbitrary(implicitly[Arbitrary[Future[A]]].arbitrary.map(FailFastFuture.apply))

implicit val throwableEq: Eq[Throwable] =
Eq.by[Throwable, String](_.toString)
Expand All @@ -63,7 +56,6 @@ class FutureTests extends CatsSuite {
checkAll("Future[Int]", MonadErrorTests[Future, Throwable].monadError[Int, Int, Int])
checkAll("Future[Int]", ComonadTests[Future].comonad[Int, Int, Int])
checkAll("Future", MonadTests[Future].monad[Int, Int, Int])
checkAll("Parallel[Future, FailFastFuture]", ParallelTests[Future, FailFastFuture].parallel[Int, String])

{
implicit val F = ListWrapper.semigroup[Int]
Expand Down
45 changes: 1 addition & 44 deletions jvm/src/test/scala/cats/tests/FutureSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ package jvm
package tests

import cats.kernel.laws.discipline.{MonoidTests => MonoidLawTests, SemigroupTests => SemigroupLawTests}
import cats.data.FailFastFuture
import cats.laws.discipline._
import cats.laws.discipline.arbitrary._
import cats.tests.{CatsSuite, ListWrapper}

import scala.concurrent.{Await, Future, blocking}
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.rng.Seed

import scala.util.{Try, Failure}

class FutureSuite extends CatsSuite {
val timeout = 3.seconds

Expand All @@ -31,14 +28,9 @@ class FutureSuite extends CatsSuite {
}
}

implicit def eqffa[A: Eq]: Eq[FailFastFuture[A]] =
Eq.by(_.value)

implicit def cogen[A: Cogen]: Cogen[Future[A]] =
Cogen[Future[A]] { (seed: Seed, t: Future[A]) => Cogen[A].perturb(seed, Await.result(t, timeout)) }

implicit def failFastArbitrary[A: Arbitrary]: Arbitrary[FailFastFuture[A]] =
Arbitrary(implicitly[Arbitrary[Future[A]]].arbitrary.map(FailFastFuture.apply))

implicit val throwableEq: Eq[Throwable] =
Eq.by[Throwable, String](_.toString)
Expand All @@ -47,44 +39,9 @@ class FutureSuite extends CatsSuite {
implicit val nonFatalArbitrary: Arbitrary[Throwable] =
Arbitrary(arbitrary[Exception].map(identity))

test("FailFastFuture should fail fast on right side") {
val exA = new Exception("A")
val exB = new Exception("B")
val fa: Future[Int] = Future {
blocking(Thread.sleep(200))
throw exA
}

val fb: Future[Int] = Future {
blocking(Thread.sleep(1))
throw exB
}

val fab: Future[Int] = (fa, fb).parMapN(_ + _)
Try(Await.result(fab, timeout)) should === (Failure(exB))
}

test("FailFastFuture should fail fast on left side") {
val exA = new Exception("A")
val exB = new Exception("B")
val fa: Future[Int] = Future {
blocking(Thread.sleep(1))
throw exA
}

val fb: Future[Int] = Future {
blocking(Thread.sleep(200))
throw exB
}

val fab: Future[Int] = (fa, fb).parMapN(_ + _)
Try(Await.result(fab, timeout)) should === (Failure(exA))
}

checkAll("Future with Throwable", MonadErrorTests[Future, Throwable].monadError[Int, Int, Int])
checkAll("Future", MonadTests[Future].monad[Int, Int, Int])
checkAll("Future", CoflatMapTests[Future].coflatMap[Int, Int, Int])
checkAll("Parallel[Future, FailFastFuture]", ParallelTests[Future, FailFastFuture].parallel[Int, String])

{
implicit val F = ListWrapper.semigroup[Int]
Expand Down

0 comments on commit 2ca66c9

Please sign in to comment.