As a brief note today, here’s some skeleton code for a ZIO (ZIO 2) application that needs to run forever. It (a) does what it needs to do, then (b) sleeps for a minute, and then (c) goes back to Step A, doing whatever it needs to do, forever.
I wanted to share this code because I think it’s probably a very common pattern and need in the ZIO world — writing an application that needs to run forever, on a schedule.
Also note that the code is written using Scala 3, but the syntax can be changed to use Scala 2, if you need to. I also added a layer/ZLayer to the code to make it a little more “real world.”
All that being said, here’s the ZIO “run forever” code: