Skip to content

Instantly share code, notes, and snippets.

@natansil
Last active May 23, 2021 19:38
Show Gist options
  • Save natansil/53e213cca096135ee10f5920a6b46329 to your computer and use it in GitHub Desktop.
Save natansil/53e213cca096135ee10f5920a6b46329 to your computer and use it in GitHub Desktop.
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
for {
fiber <- runSomeLongJob
.ensuring(printWithTime("finalizing job!"))
.forkDaemon
_ <- printWithTime("do stuff").repeat(Schedule.spaced(1.seconds) && Schedule.recurs(2))
timeout <- fiber.join.resurrect.ignore.disconnect.timeout(5.seconds)
_ <- ZIO.when(timeout.isEmpty)(fiber.interruptFork)
_ <- printWithTime("do other stuff").repeat(Schedule.spaced(1.seconds))
} yield ExitCode(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment