Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] isTaskPending #56

Open
Jamesernator opened this issue Nov 30, 2021 · 0 comments
Open

[Suggestion] isTaskPending #56

Jamesernator opened this issue Nov 30, 2021 · 0 comments

Comments

@Jamesernator
Copy link

From other proposals we have isFramePending and isInputPending however it would also be useful to have a more general isTaskPending which returns true if any task of higher priority is scheduled to run. This would also include tasks created by the browser, i.e. isInputPending() and isFramePending() would both imply isTaskPending().

The usage would be similar to is{Input,Frame}Pending:

await scheduler.postTask(async function createNoiseTexture() {
    const texture = new Texture(1000, 1000);
    
    for (let x = 0; i < texture.width; x += 1) {
       for (let y = 0; i < texture.height; x += 1) {
           // Allow any higher priority tasks to run, or frame tasks
           // or input tasks as well (and possibly other browser tasks as well)
           if (scheduler.isTaskPending("background")) {
               await scheduler.yield("background");
           }
           texture.setPixel(x, y, generateNoiseRGB());
       }
    }
}, { priority: "background" });
@Jamesernator Jamesernator changed the title isTaskPending [Proposal] isTaskPending Nov 30, 2021
@Jamesernator Jamesernator changed the title [Proposal] isTaskPending [Suggestion] isTaskPending Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant