skedule
skedule copied to clipboard
Recurring execution of Schedule's
I think a method like this would be quite helpful:
fun Schedule.schedule(executor: ThreadPoolExecutor, code: () -> Unit) {
val now = ZonedDateTime.now()
val next = this.next(
now
.minusSeconds(now.second.toLong())
.minusNanos(now.nano.toLong())
)
val delay = next.toEpochSecond() - now.toEpochSecond()
executor.schedule(
{
this.schedule(code)
code()
},
delay,
TimeUnit.SECONDS
)
}
because the example in the README.md is not recurring
I don't like the idea of mixing in ThreadPoolExecutor
(which is a Java class), you could use a Kotlin coroutine instead