Skip to content

Commit

Permalink
Window.set/clearImmediate deprecated (#29568)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee authored Oct 10, 2023
1 parent 7073233 commit 6fa75c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
12 changes: 6 additions & 6 deletions files/en-us/web/api/window/clearimmediate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ title: "Window: clearImmediate() method"
short-title: clearImmediate()
slug: Web/API/Window/clearImmediate
page-type: web-api-instance-method
status:
- deprecated
- non-standard
browser-compat: api.Window.clearImmediate
---

{{APIRef("HTML DOM")}}
{{APIRef("HTML DOM")}} {{deprecated_header}}

This method clears the action specified by {{DOMxRef("window.setImmediate")}}.

> **Note:** This method is not expected to become standard, and is nowadays only implemented
> by Node.js 0.10+. It meets resistance both from [Gecko](https://bugzil.la/686201) (Firefox) and [Chromium/WebKit](https://crbug.com/146172) (Chrome/Safari).
## Syntax

```js-nolint
Expand Down Expand Up @@ -43,8 +43,8 @@ document.getElementById("button").addEventListener(() => {

## Specifications

Not part of any current specifications. The
[Efficient Script Yielding](https://w3c.github.io/setImmediate/#si-setImmediate)
Not part of any current specifications.
The [Efficient Script Yielding](https://w3c.github.io/setImmediate/#si-setImmediate)
specification is no longer being worked on.

## Browser compatibility
Expand Down
4 changes: 2 additions & 2 deletions files/en-us/web/api/window/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ _This interface inherits methods from the {{domxref("EventTarget")}} interface._
- : Enables you to cancel a callback previously scheduled with {{domxref("Window.requestAnimationFrame")}}.
- {{domxref("Window.cancelIdleCallback()")}}
- : Enables you to cancel a callback previously scheduled with {{domxref("Window.requestIdleCallback")}}.
- {{domxref("Window.clearImmediate()")}}
- {{domxref("Window.clearImmediate()")}} {{Non-standard_Inline}} {{Deprecated_Inline}}
- : Cancels the repeated execution set using `setImmediate()`.
- {{domxref("clearInterval", "Window.clearInterval()")}}
- : Cancels the repeated execution set using {{domxref("setInterval()")}}.
Expand Down Expand Up @@ -237,7 +237,7 @@ _This interface inherits methods from the {{domxref("EventTarget")}} interface._
- : Scrolls the current document by the specified number of pages.
- {{domxref("Window.scrollTo()")}}
- : Scrolls to a particular set of coordinates in the document.
- {{domxref("Window.setImmediate()")}}
- {{domxref("Window.setImmediate()")}} {{Non-standard_Inline}} {{Deprecated_Inline}}
- : Executes a function after the browser has finished other heavy tasks.
- {{domxref("setInterval", "Window.setInterval()")}}
- : Schedules a function to execute every time a given number of milliseconds elapses.
Expand Down
28 changes: 10 additions & 18 deletions files/en-us/web/api/window/setimmediate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ title: "Window: setImmediate() method"
short-title: setImmediate()
slug: Web/API/Window/setImmediate
page-type: web-api-instance-method
status:
- deprecated
- non-standard
browser-compat: api.Window.setImmediate
---

{{APIRef("HTML DOM")}}
{{APIRef("HTML DOM")}} {{deprecated_header}}

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.

> **Note:** This method is not expected to become standard, and is nowadays only implemented
> by Node.js 0.10+. It meets resistance both from [Gecko](https://bugzil.la/686201) (Firefox) and [Chromium/WebKit](https://crbug.com/146172) (Chrome/Safari).
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

Expand All @@ -39,29 +37,23 @@ The ID of the immediate which can be used later with {{DOMxRef("window.clearImme

## Notes

The {{DOMxRef("Window.clearImmediate", "clearImmediate")}} method can be used to clear
the immediate actions, just like {{DOMxRef("clearTimeout")}} for
{{DOMxRef("setTimeout()")}}.
The {{DOMxRef("Window.clearImmediate", "clearImmediate")}} method can be used to clear the immediate actions, just like {{DOMxRef("clearTimeout")}} for {{DOMxRef("setTimeout()")}}.

This method can be used instead of the `setTimeout(fn, 0)` method to execute
[heavy operations](https://humanwhocodes.com/blog/2009/08/11/timed-array-processing-in-javascript/).
This method can be used instead of the `setTimeout(fn, 0)` method to execute [heavy operations](https://humanwhocodes.com/blog/2009/08/11/timed-array-processing-in-javascript/).

The feature can be emulated in a few different ways:

- {{DOMxRef("Window.postMessage", "postMessage")}} can be used to trigger an immediate but yielding callback.
- {{DOMxRef("MessageChannel")}} can be used reliably inside of Web Workers whereas the
semantics 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 deep [per the HTML spec](https://html.spec.whatwg.org/multipage/webappapis.html#timers), it does not make for a suitable polyfill for the natural immediacy of
`setImmediate`.
- `setTimeout(fn, 0)` _can_ potentially be used, however as it is clamped to 4ms for timers nested more than 5 levels deep [per the HTML spec](https://html.spec.whatwg.org/multipage/webappapis.html#timers), it does not make for a suitable polyfill for the natural immediacy of `setImmediate`.

All of these techniques are incorporated into a [robust setImmediate polyfill](https://github.com/YuzuJS/setImmediate).

## Specifications

Not part of any current specifications. The
[Efficient Script Yielding](https://w3c.github.io/setImmediate/#si-setImmediate)
specification is no longer being worked on.
Not part of any current specifications.
The [Efficient Script Yielding](https://w3c.github.io/setImmediate/#si-setImmediate) specification is no longer being worked on.

## Browser compatibility

Expand Down

0 comments on commit 6fa75c6

Please sign in to comment.