// Create a TaskController with default priority: 'user-visible'
const controller = new TaskController();TaskController: setPriority() method / notebook
TaskController: setPriority() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// Post task passing the controller's signal.
// The signal priority sets the initial priority of the task
scheduler
.postTask(() => "Task execute", { signal: controller.signal })
.then((taskResult) => {
console.log(`${taskResult}`);
}) // Run on success)
.catch((error) => {
console.log(`Catch error: ${error}`);
}); // Run on fail// Change the priority to 'background' using the controller
controller.setPriority("background");