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

use Prioritized Task Scheduling API #66

Open
DrSensor opened this issue Apr 27, 2023 · 1 comment
Open

use Prioritized Task Scheduling API #66

DrSensor opened this issue Apr 27, 2023 · 1 comment
Labels
optimization Because speed, memory consumption, and bundle size are important
Milestone

Comments

@DrSensor
Copy link
Owner

refactor/delete core/task.js and use scheduler.postTask

@DrSensor DrSensor added this to the 1.0.0 milestone Apr 27, 2023
@DrSensor DrSensor added the optimization Because speed, memory consumption, and bundle size are important label Apr 27, 2023
@DrSensor
Copy link
Owner Author

DrSensor commented Sep 13, 2024

behold, scheduler.yield is out and it can inherit abort signal from scheduler.postTask

example

let controller;

async function longTask() {
  try {
    blockMainThread(500);

    // Yield the task using the scheduler, passing the signal from the controller
    // The "inherit" option means the task will inherit the signal from its parent
    await scheduler.yield({ signal: "inherit" });

    // If the user cancels the task, the code below will not run
    blockMainThread(500);
  } catch (error) {
    if (error.name === "AbortError") {
    // Handle the abort
  }
}
}

startButton.addEventListener("click", () => {
  controller = new TaskController();

  // Post the longTask to the scheduler, passing the signal from the controller
  scheduler.postTask(longTask, {
    signal: controller.signal,
  });
});

cancelButton.addEventListener("click", () => {
  if (controller) {
    controller.abort();
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Because speed, memory consumption, and bundle size are important
Development

No branches or pull requests

1 participant