diff --git a/source b/source index 2c34d4ef2ce..73fc43bb13c 100644 --- a/source +++ b/source @@ -4110,6 +4110,17 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute +
The following feature is defined in the Cooperative Scheduling of Background + Tasks specification:
+ +requestIdleCallback()
To affect the world of observable JavaScript objects, then, you must queue a task to perform any such manipulations. This ensures your steps are properly interleaved with respect to other things happening on the event loop. Furthermore, you must choose a - task source when queueing a task; this governs the + task source when queuing a task; this governs the relative order of your steps versus others. If you are unsure which task source to use, pick one of the generic task sources that sounds most applicable.
@@ -89366,7 +89377,7 @@ dictionary PromiseRejectionEventInit : EventInit { algorithms to be invoked in contexts involving multiple event loops. (Unlike contexts involving multiple global objects, which happen all the time!) So unless you are writing a specification which, e.g., deals with manipulating workers, you can omit this argument - when queueing a task. + when queuing a task.Putting this all together, we can provide a template for a typical algorithm that needs to do work asynchronously:
@@ -90375,6 +90386,9 @@ interface mixin WindowOrWorkerGlobalScope { long setInterval(TimerHandler handler, optional long timeout = 0, any... arguments); void clearInterval(optional long handle = 0); + // microtask queuing + void queueMicrotask(Function callback); + // ImageBitmap Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, optional ImageBitmapOptions options); Promise<ImageBitmap> createImageBitmap(ImageBitmapSource image, long sx, long sy, long sw, long sh, optional ImageBitmapOptions options); @@ -91291,6 +91305,37 @@ scheduleWork(); // queues a task to do lots of work +The queueMicrotask()
method allows authors to schedule
+ a callback on the microtask queue. This allows their code to run after the
+ currently-executing task has run to completion and the
+ JavaScript execution context stack is empty, but without yielding control back to the
+ browser's event loop, as would be the case when using, for example, setTimeout(f, 0)
.
Authors should be aware that scheduling a lot of microtasks has the same performance downsides
+ as running a lot of synchronous code. Both will prevent the browser from doing its own work, such
+ as rendering or scrolling. In many cases, requestAnimationFrame()
or
+ requestIdleCallback()
is a better choice. In particular, if the goal is to run code
+ before the next rendering cycle, that is the purpose of requestAnimationFrame()
.
queueMicrotask
(callback)Queues a microtask to run the given + callback.
The queueMicrotask(callback)
method must
+ queue a microtask to invoke
+ callback, and if callback throws an exception, report the
+ exception.