Skip to content

Instantly share code, notes, and snippets.

@cquiroz
Created March 18, 2019 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cquiroz/d989bb3320c0ed0a644fbd8b0c327c01 to your computer and use it in GitHub Desktop.
Save cquiroz/d989bb3320c0ed0a644fbd8b0c327c01 to your computer and use it in GitHub Desktop.
ResourceIOApp.scala
import cats.effect._
import cats.implicits._
object Launcher extends IOApp {
def run(args: List[String]): IO[ExitCode] = {
val launchMissiles = IO.raiseError[Unit](new Exception("boom!"))
val runToBunker = IO(println("To the bunker!!!"))
val p: IO[Unit] = for {
fiber <- launchMissiles.start
_ <- runToBunker.handleErrorWith { error =>
// Retreat failed, cancel launch (maybe we should
// have retreated to our bunker before the launch?)
fiber.cancel *> IO.raiseError[Unit](error)
}
aftermath <- fiber.join
} yield aftermath
val r: Resource[IO, ExitCode] =
for {
_ <- Resource.liftF(p) // Initialize log before the engine is setup
} yield ExitCode.Success
r.use(_ => IO.never)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment