-
Notifications
You must be signed in to change notification settings - Fork 47
Description
As pointed out in WebKit/standards-positions#361, scheduler.render()
is inconsistently named with .wait()
and .yield()
because the method doesn't actually render.
Some additional concerns that came up in discussion:
.wait()
(as well as.waitForRender()
) is a bit awkward withawait
, and that will probably be more common then.wait().then(...)
(which does read well).render()
is ambiguous: is the promise resolved before, during, or after rendering?- The APIs should use the same part of speech, per https://www.w3.org/TR/design-principles/#naming-consistency
Trying to alleviate all of these concerns is tricky, but here's an attempt:
async function task() {
await scheduler.continuation();
await scheduler.timeout(1000);
await scheduler.nextFrame();
}
.wait()
: .timeout()
represents what you're waiting for, and it's in line with both setTimeout()
and AbortSignal.timeout()
.
.yield()
: If .wait()
becomes .timeout()
, this should be a noun too (per (3)). The promise returned by .yield()
represents a continuation of the current task, and awaiting a continuation is yielding, so .continuation()
seems natural. I'm a little worried that .continuation()
will be less intuitive for developers than .yield()
, but maybe that's a documentation problem?
.render()
: This is tricky because "rendering" is both the relevant noun ("update the rendering") and verb ("render"), which makes await scheduler.rendering()
awkward and ambiguous. I chose .nextFrame()
because I think it aligns with the LoAF processing model: in LoAF, the frame timing is reset after the task if no documents need rendering, or after rendering if they do. That matches the the intended behavior of the promise resolution for this API.