Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Scheduler

Limited availability

Note: This feature is available inWeb Workers.

TheScheduler interface of thePrioritized Task Scheduling API provides methods for scheduling prioritized tasks.

AScheduler can be accessed from the global object usingWindow.scheduler orWorkerGlobalScope.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 theglobalThis 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 acatch block, which would be required in more complex code to handle when a task is aborted or throws an error.

js
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 seePrioritized Task Scheduling API > Examples.

Specifications

Specification
Prioritized Task Scheduling
# scheduler

Browser compatibility

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp