WICG/scheduling-apis

Recurring schedules?

benlesh opened this issue · 2 comments

I didn't see anything about how this API will allow the scheduling of recurring tasks, like an interval, which has a different behavior than recursively scheduling one task at a time could ever provide. Did I just miss it? Also how does prioritization fit in there?

(Apologies, this fell off my radar.)

The API does support an option for delayed tasks, but we haven't added an option for recurring tasks yet (i.e. we essentially have prioritized setTimeout but not setInterval). Being able to post (prioritized) delayed tasks is something that came up in designing this API, but intervals not so much (so far). But, I'd imagine for consistency we'd include this as well, maybe something like:

scheduler.postTask(foo, {delay: 1000, repeating: true})

?

As far as how prioritization fits in: the tasks are queued when the delay expires (similar to how setTimeout works). So the delta between a task's delay expiring and when it starts depends on thread congestion, and that delta should be a bit smaller on average for delayed user-blocking tasks (they'd run before currently queued user-visible and background tasks).

This would be nice to add, doing the alignment math yourself is not something I think most folks would figure out:

https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/timer.cc;l=155;drc=48ee6c4ee320c1bcc4f7d01d5c293e6d41ecf648;bpv=0;bpt=1