Skip to content

LiftIO Instances for Future and Rerunnable #221

@bpholt

Description

@bpholt

Would LiftIO instances for Future and Rerunnable be welcomed? I couldn't find laws for LiftIO but these rough implementations seemed to work after some limited testing I did.

implicit val rerunnableLiftIO: LiftIO[Rerunnable] = new LiftIO[Rerunnable] {
  override def liftIO[A](ioa: IO[A]): Rerunnable[A] =
    Rerunnable.fromFuture(LiftIO[Future].liftIO(ioa))
}

implicit val futureLiftIO: LiftIO[Future] = new LiftIO[Future] {
  override def liftIO[A](ioa: IO[A]): Future[A] = {
    val p = Promise[A]

    ioa.unsafeRunAsync {
      case Left(ex) => p.setException(ex)
      case Right(a) => p.setValue(a)
    }

    p
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions