As a brief note today, here’s a little ZIO 2 example that shows how to print a series of values with a random delay in between each value that’s printed.
Also note that in the code below there are different ways to implement randomWaitTimeInSeconds ... for instance, it could return a Duration, but I just have it return an Int.
I also use ZIO.foreach to generate the values in a range, and that could be handled differently.
Another thing I do is use an exception inside ZIO.fail, and I do that because I want that error to be a Throwable on the ZIO “error channel” (i.e., the E parameter in ZIO[R, E, A].)