Not sure what the problem is but this code sample hangs under some conditions (documented below).
package thiswillhang
import cats._
import cats.effect._
/**
* This will hang if run with both flags. Why?
*
* {{{
* sbt "run resource raise"
* }}}
*/
object ThisWillHang extends IOApp {
type ApplicativeErrorThrowable[F[_]] = ApplicativeError[F, Throwable]
def run(args: List[String]): IO[ExitCode] =
for {
n <- acquireIOInt[IO](args)
_ <- doPrint[IO](n)
} yield ExitCode.Success
def acquireIOInt[F[_]](args: List[String])(implicit F: Sync[F]): F[Int] = {
val err =
ApplicativeError[F, Throwable]
.fromEither(buildErr(args.contains("raise")))
if (args.contains("resource"))
Resource
.liftF(err)
.use(F.pure)
else
err
}
def buildErr(doHang: Boolean): Either[Throwable, Int] =
if (doHang)
Left(new IllegalArgumentException("hey"))
else
Right(12345)
def doPrint[F[_]](n: Int)(implicit F: Sync[F]): F[Unit] =
F.delay {
println(n)
}
}
Yes, errors in resource acquisition can cause IOApp to hang. I reported a similar thing and @SystemFw said it's a known problem in cats-effect that he thought would be fixed soon 鈥β燜abio can you comment?
Please see here for more details https://github.com/typelevel/cats-effect/issues/487. A release of the fix is planned soon as confirmed here
Great! Filed in the wrong repo anyway. Closing as dupe.
Confirmed fixed in newly available cats-effect 1.3.0
Most helpful comment
Confirmed fixed in newly available
cats-effect1.3.0