Skip to content

Instantly share code, notes, and snippets.

@natansil
Last active May 17, 2021 14:28
Show Gist options
  • Save natansil/8763a0d11dda1db83b4ccd99947c6f62 to your computer and use it in GitHub Desktop.
Save natansil/8763a0d11dda1db83b4ccd99947c6f62 to your computer and use it in GitHub Desktop.
object DefectNotHandledExample extends App {
import zio._
import zio.duration._
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
for {
_ <- runSomePeriodicJob
.catchAll(e => console.putStrLn(s"job failed with $e"))
.repeat(Schedule.spaced(1.seconds))
.forkDaemon
_ <- console.putStrLn("do other stuff")
.repeat(Schedule.spaced(1.seconds))
} yield ExitCode(0)
private def runSomePeriodicJob = {
ZIO.succeed(throw new RuntimeException("unexpected defect")) *> ZIO.effect(println("running job..."))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment