Last active
February 3, 2026 20:25
-
-
Save dacr/73844b0551bb49dacf03ad05c573f485 to your computer and use it in GitHub Desktop.
ZIO live session - Make execution resilient / published by https://github.com/dacr/code-examples-manager #b437a3c2-257b-4346-89fd-f6632c5d2d60/3f1e855d4fc0cb895ff84b3ed125393d3de8dce0
This file contains hidden or 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
| // summary : ZIO live session - Make execution resilient | |
| // keywords : scala, zio, live, demo, pure-functional, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : b437a3c2-257b-4346-89fd-f6632c5d2d60 | |
| // created-on : 2021-09-26T16:27:18+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "dev.zio::zio:2.0.13" | |
| //> using dep "fr.janalyse::zio-worksheet:2.0.13.0" | |
| // --------------------- | |
| import zio.*, zio.worksheet.*, scala.util.Random.nextInt, scala.util.Try | |
| import scala.Console.{GREEN,RED,RESET} | |
| // 42 / nextInt(2) | |
| Try(42 / nextInt(2)) | |
| val logic = ZIO.attempt(42 / nextInt(2)) | |
| logic | |
| .tapError(result => Console.printLine(s"1.${RED} FAILED$RESET")) | |
| .tap(result => Console.printLine(s"1.${GREEN} SUCCESS$RESET")) | |
| .ignore | |
| .unsafeRun // ONLY FOR WORKSHEET PURPOSES | |
| logic | |
| .retry(Schedule.forever) | |
| .tapError(result => Console.printLine(s"2.${GREEN} FAILED$RESET")) | |
| .tap(result => Console.printLine(s"1.${GREEN} SUCCESS$RESET")) | |
| .unsafeRun // ONLY FOR WORKSHEET PURPOSES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment