Skip to content

Yieldy API Naming #95

@shaseley

Description

@shaseley

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:

  1. .wait() (as well as .waitForRender()) is a bit awkward with await, and that will probably be more common then .wait().then(...) (which does read well)
  2. .render() is ambiguous: is the promise resolved before, during, or after rendering?
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions