WindowOrWorkerGlobalScope.queueMicrotask

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

The queueMicrotask() method of the WindowOrWorkerGlobalScope mixin queues a microtask.

Syntax

scope.queueMicrotask(function);

Parameters

function
A function to be executed.

Polyfill

if (typeof window.queueMicrotask !== "function") {
  window.queueMicrotask = function (callback) {
    Promise.resolve()
      .then(callback)
      .catch(e => setTimeout(() => { throw e; }));
  };
}

Notes

Infinite loops

A microtask posted with queueMicrotask may itself queue another microtask, thus possibly creating an infinite loop. This will cause the page to become unresponsive.

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'self.queueMicrotask()' in that specification.
Living Standard Initial definition

Browser compatibility

No compatibility data found. Please contribute data for "api.WindowOrWorkerGlobalScope.queueMicrotask" (depth: 1) to the MDN compatibility data repository.

Since Chrome 71: https://www.chromestatus.com/feature/5111086432911360
Since Node.js v11.0.0: https://nodejs.org/api/globals.html#globals_queuemicrotask_callback
Since Safari 12.1
Since Firefox 69

See also

文档标签和贡献者

此页面的贡献者: DomenicDenicola, zbjornson
最后编辑者: DomenicDenicola,