Created
March 18, 2019 12:19
-
-
Save cquiroz/d989bb3320c0ed0a644fbd8b0c327c01 to your computer and use it in GitHub Desktop.
ResourceIOApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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