Jörg Winter
11/12/2022, 10:44 AMfun mytimer() = Schedule.forever<String>().delay { duration ->
Duration.Companion.seconds(5)
}
Hi all,
What is the input argument 'duration'.. when has it a value other than 0s (in this example it is always 0s) ?simon.vergauwen
11/12/2022, 10:49 AMSchedule.forever
is the equivalent of while(true)
.
In contrast Schedule.spaced(5.seconds)
is Schedule.forever
with a constant delay in between every loop of 5s.
Schedule.linear(5.seconds)
builds a linear delay schedule with an initial value of 5.seconds
.Jörg Winter
11/12/2022, 11:01 AM@OptIn(ExperimentalTime::class)
fun mytimer() = Schedule.linear<Unit>(1.seconds).modify { n, duration ->
val nextDuration = duration.plus(1.seconds) // or determine next duration however you want...
nextDuration
}
Jörg Winter
11/12/2022, 11:01 AMsimon.vergauwen
11/12/2022, 1:14 PMlinear
constructor already does. It relies on forever
which outputs the count of it's iteration and multiplies it with the base = 1.seconds
.
delayed(forever<A>().map { base * it })
simon.vergauwen
11/12/2022, 1:16 PMSchedule
is that it already exposes most of the things you need, and you can compose different pieces together. I.e. Schedule.linear(1.seconds).jittered() and Schedule.recurs(5)
will have a jittered linear back-off delay, with a max of 5 tries.
So if you use it as Schedule.linear(1.seconds).jittered() and Schedule.recurs(5).retry { f() }
it will retry f
5 times with a jittered linear back-off.