Is it possible to have a delayed Schedule before the first attempt only ? I thought something like this would work but i triggers the function eagerly immediately:
Copy code
private suspend fun scheduleWithInitialDelay(job: Job, block: suspend () -> Unit) {
// Repeat every 5 minutes
Schedule.spaced<Unit>(job.fixedInterval)
.delayed { attempt, _ ->
// Delay by 1 minute only for the first attempt
if (attempt == 0L) job.initialDelay else ZERO
}
.repeat { block() }
}
s
Stylianos Gakis
11/29/2024, 9:11 PM
So do you want to simply delay your first attempt?
Does adding a simple delay first thing in the function do what you want here?
k
Kristian Frøhlich
11/29/2024, 9:27 PM
Yeah, as described inline. Only an initial delay before a fixed schedule kicks in. Delaying in the function would also delay all subsequent calls which i want to avoid
s
Stylianos Gakis
11/29/2024, 10:02 PM
So you want the action to run on minutes:
1 - 5 - 10 - 15 - 20
But not
0 - 5 - 10 - 15 - 20
or
1 - 6 - 11 - 16 - 21