Permalink
Browse files

Add generic futureToAsync and define rerunnableToIO in terms of it.

  • Loading branch information...
ben-healthforge authored and travisbrown committed Jun 2, 2018
1 parent b79eafb commit 1c2bd0687498ba4ab6e1648c69c68c5b8ddec506
Showing with 6 additions and 4 deletions.
  1. +6 −4 effect/src/main/scala/io/catbird/util/effect/package.scala
@@ -1,15 +1,17 @@
package io.catbird.util
import cats.effect.IO
import com.twitter.util.{ Return, Throw }
import cats.effect.{ Async, IO }
import com.twitter.util.{ Future, Return, Throw }
import java.lang.Throwable
import scala.util.{ Left, Right }
package object effect extends RerunnableInstances {
final def rerunnableToIO[A](fa: Rerunnable[A]): IO[A] = IO.async { k =>
fa.run.respond {
def futureToAsync[F[_], A](fa: => Future[A])(implicit F: Async[F]): F[A] = F.async { k =>
fa.respond {
case Return(a) => k(Right[Throwable, A](a))
case Throw(err) => k(Left[Throwable, A](err))
}
}
final def rerunnableToIO[A](fa: Rerunnable[A]): IO[A] = futureToAsync[IO, A](fa.run)
}

0 comments on commit 1c2bd06

Please sign in to comment.