Reputation: 79
The schedule I'm trying to make would have to:
So what I have is (2.) and (3.):
val repeatUntilTimeLimitReached =
ZSchedule
.fixed(config.pollingConfig.pollInterval)
.untilOutput(pollingTimeLimitReached)
val untilTermination = Schedule.doUntil[RebootState](_.terminatesPolling)
val schedule = repeatUntilTimeLimitReached *> untilTermination
I tried ZSchedule.delayed()
, but it seems to add delay to subsequent schedules too.
So is there any way to add intial delay to ZSchedule
?
Upvotes: 2
Views: 1880
Reputation: 14803
Why not add another Schedule and compose them:
val delayedSchedule = Schedule.once.delayed(_ + 12.seconds)
val schedule = delayedSchedule *> repeatUntilTimeLimitReached *> untilTermination
I played a bit with this and you need to flatMap
the Schedules.
Here I use an example that uses zio.console
:
import zio.console._
import zio.duration._
import zio.{App, Schedule, ZIO}
val s = Schedule.spaced(1.second)
for {
_ <- putStrLn("Start")
_ <- putStrLn("Initial Delay").delay(5.seconds)
_ <- putStrLn("Repeated Delay").repeat(s)
} yield ()
Upvotes: 1
Reputation: 79
After having a small discussion with community it seems that expected behaviour is not achievable with Schedule
(ZIO version: 1.0.0-RC15), since it is used to repeat after the first execution.
I've ended up using ZIO.sleep()
and schedule
I made in the original post:
val schedule = repeatUntilTimeLimitReached *> untilTermination
for {
_ <- ZIO.sleep(initialDelay)
state <- doStuff().repeat(schedule)
} yield state
Upvotes: 2