A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/API/Scheduler below:

Scheduler - Web APIs | MDN

Scheduler

Limited availability

Note: This feature is available in Web Workers.

The Scheduler interface of the Prioritized Task Scheduling API provides methods for scheduling prioritized tasks.

A Scheduler can be accessed from the global object using Window.scheduler or WorkerGlobalScope.scheduler within a worker.

Instance properties

None.

Instance methods
Scheduler.postTask()

Adds a task to the scheduler as a callback, optionally specifying a priority, delay, and/or a signal for aborting the task.

Scheduler.yield() Experimental

Yields control of the main thread back to the browser, returning a promise that resolves to continue execution where it left off.

Examples

If the feature is defined, an instance of this object is returned by the globalThis property in both workers and the main thread.

The code below shows a simple task that resolves with the text 'Task executing'. This text is logged on success. The code also shows a catch block, which would be required in more complex code to handle when a task is aborted or throws an error.

if ("scheduler" in this) {
  // Post task with default priority: 'user-visible' (no other options)
  // When the task resolves, Promise.then() logs the result.
  scheduler
    .postTask(() => "Task executing")
    .then((taskResult) => console.log(`${taskResult}`)) // Log result
    .catch((error) => console.error(`Error: ${error}`)); // Log errors
}

For more comprehensive example code see Prioritized Task Scheduling API > Examples.

Specifications Browser compatibility

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3