I stumbled upon something which i’m not sure if it...
# arrow
i
I stumbled upon something which i’m not sure if it’s a bug or not:
Schedule.delayed
and
jittered()
only change the first pause, every pause after that comes from the original schedule.
Copy code
import arrow.resilience.Schedule
import arrow.resilience.Schedule.Decision.Continue
import kotlinx.coroutines.runBlocking
import kotlin.time.Duration.Companion.seconds

fun main() = runBlocking {
    suspend fun Schedule<Unit, *>.pauses() = buildList {
        var step = step
        repeat(5) { (step(Unit) as Continue<Unit, *>).also { add(it.delay); step = it.step } }
    }
    val spaced = Schedule.spaced<Unit>(10.seconds)
    println("spaced                    ${spaced.pauses()}")
    println("spaced.delayed { d * 2 }  ${spaced.delayed { _, d -> d * 2 }.pauses()}")
    println("spaced.jittered()         ${spaced.jittered().pauses()}")
    println("spaced.mapDecision(* 2)   ${spaced.mapDecision { if (it is Continue) Continue(it.output, it.delay * 2, it.step) else it }.pauses()}")
}
Copy code
spaced                    [10s, 10s, 10s, 10s, 10s]
spaced.delayed { d * 2 }  [20s, 10s, 10s, 10s, 10s]
spaced.jittered()         [6.507837879s, 10s, 10s, 10s, 10s]
spaced.mapDecision(* 2)   [20s, 20s, 20s, 20s, 20s]
my 🤖 said
The cause is
Decision.delayed
, which hands back the original
step
without wrapping it:
Continue(output, transform(output, delay), step)
.
map
,
contramap
and
recursiveMap
all wrap the next step.
This also affects `HttpRequestSchedule`’s default,
exponential(2.seconds).jittered()
, which jitters only its first retry.
mapDecision
works as expected.
minimal repro attahced
👀 1
a
cc @simon.vergauwen
👀 1
@Ido Flax may you open an issue report?
i
Sure. FYI i sent this to simon already 🫡
@simon.vergauwen / @Alejandro Serrano.Mena Is this going to be released soon?
a
sorry, I’m a bit dumped right now, I’ll try to get this out coming weekend
i
No pressure, thanks!