Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: setImmediate() method

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

This method is used to break up long running operations and run a callback function immediately after the browser has completed other operations such as events and display updates.

Syntax

js
setImmediate(func)setImmediate(func, param1)setImmediate(func, param1, param2)setImmediate(func, param1, param2, /* …, */ paramN)

Parameters

func

The function you wish to call.

param1, …,paramN

All parameters will be passed directly to your function.

Return value

The ID of the immediate which can be used later withwindow.clearImmediate.

Notes

TheclearImmediate() method can be used to clear the immediate actions, just likeclearTimeout() forsetTimeout().

This method can be used instead of thesetTimeout(fn, 0) method to executeheavy operations.

The feature can be emulated in a few different ways:

  • postMessage() can be used to trigger an immediate but yielding callback.
  • MessageChannel can be used reliably inside of Web Workers whereas thesemantics of postMessage mean it cannot be used there.
  • setTimeout(fn, 0)can potentially be used, however as it is clamped to 4ms for timers nested more than 5 levels deepper the HTML spec, it does not make for a suitable polyfill for the natural immediacy ofsetImmediate.

All of these techniques are incorporated into arobust setImmediate polyfill.

Specifications

Not part of any current specifications.TheEfficient Script Yielding specification is no longer being worked on.

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp