Skip to content

Commit

Permalink
Added runAsync handler law
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Jun 18, 2017
1 parent 5490053 commit 09e64a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions laws/shared/src/main/scala/cats/effect/laws/EffectLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ trait EffectLaws[F[_]] extends AsyncLaws[F] {
F.runAsync(fa)(e => IO { result = Some(e) }) >> read <-> IO.pure(Left(e))
}

def runAsyncIgnoresErrorInHandler[A](e: Throwable) = {
val fa = F.pure(())
F.runAsync(fa)(_ => IO.raiseError(e)) <-> IO.pure(())
}

def repeatedCallbackIgnored[A](a: A, f: A => A) = {
var cur = a
val change = F.delay(cur = f(cur))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ trait EffectTests[F[_]] extends AsyncTests[F] {
EqFABC: Eq[F[(A, B, C)]],
EqFInt: Eq[F[Int]],
EqIOA: Eq[IO[A]],
EqIOU: Eq[IO[Unit]],
EqIOEitherTA: Eq[IO[Either[Throwable, A]]],
iso: Isomorphisms[F]): RuleSet = {
new RuleSet {
Expand All @@ -59,6 +60,7 @@ trait EffectTests[F[_]] extends AsyncTests[F] {
val props = Seq(
"runAsync pure produces right IO" -> forAll(laws.runAsyncPureProducesRightIO[A] _),
"runAsync raiseError produces left IO" -> forAll(laws.runAsyncRaiseErrorProducesLeftIO[A] _),
"runAsync ignores error in handler" -> forAll(laws.runAsyncIgnoresErrorInHandler[A] _),
"repeated callback ignored" -> forAll(laws.repeatedCallbackIgnored[A] _))
}
}
Expand Down

0 comments on commit 09e64a7

Please sign in to comment.