Atomics.waitAsync()

Baseline 2025
Newly available

Since November 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The Atomics.waitAsync() static method verifies that a shared memory location contains a given value, immediately returning an object with the value property containing the string "not-equal" if the memory location does not match the given value, or "timed-out" if the timeout was set to zero. Otherwise the method returns an object where the value property is a Promise that fulfills with either "ok" when Atomics.notify() is called, or "timed-out" if the timeout expires.

Atomics.waitAsync() and Atomics.notify() are used together to enable thread synchronization based on a value in shared memory. A thread can proceed immediately if the synchronization value has changed, or it can wait for notification from another thread when it reaches the synchronization point.

This method only works with an Int32Array or BigInt64Array that views a SharedArrayBuffer. It is non-blocking and, unlike Atomics.wait(), can be used on the main thread. Because it does not block the whole thread, you still need to be careful not to access the shared memory before the promise settles.

Syntax

js
Atomics.waitAsync(typedArray, index, value)
Atomics.waitAsync(typedArray, index, value, timeout)

Parameters

typedArray

An Int32Array or BigInt64Array that views a SharedArrayBuffer.

index

The position in the typedArray to wait on.

value

The expected value to test.

timeout Optional

Time to wait in milliseconds. NaN (and values that get converted to NaN, such as undefined) becomes Infinity. Negative values become 0.

Return value

An Object with the following properties:

async

A boolean indicating whether the value property is a Promise or not.

value

If async is false, it will be a string which is either "not-equal" or "timed-out" (only when the timeout parameter is 0). If async is true, it will be a Promise which is fulfilled with a string value, either "ok" or "timed-out". The promise is never rejected.

Exceptions

TypeError

Thrown if typedArray is not an Int32Array or BigInt64Array that views a SharedArrayBuffer.

RangeError

Thrown if index is out of bounds in the typedArray.

Examples

Note that these examples cannot be run directly from the console or an arbitrary web page, because SharedArrayBuffer is not defined unless its security requirements are met.

Using Atomics.waitAsync()

Given a shared Int32Array:

js
// Create a SharedArrayBuffer with a size in bytes
const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);

A reading thread is sleeping and waiting on location 0 which is expected to be 0. The result.value will be a promise.

js
const result = Atomics.waitAsync(int32, 0, 0, 1000);
// { async: true, value: Promise {<pending>} }

In the reading thread or in another thread, the memory location 0 is called and the promise can be resolved with "ok".

js
Atomics.notify(int32, 0);
// { async: true, value: Promise {<fulfilled>: 'ok'} }

If it isn't resolving to "ok", the value in the shared memory location wasn't the expected (the value would be "not-equal" instead of a promise) or the timeout was reached (the promise will resolve to "time-out").

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-atomics.waitasync

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
waitAsync
Chrome – Partial support
Chrome 87 – 89 (Release date: 2020-11-17)
footnote Partial support
footnote The Atomics.waitAsync() method never times out. See bug 40742782.
Chrome – Full support
Chrome 90 (Release date: 2021-04-13)
footnote Full support
Edge – Partial support
Edge 87 – 89 (Release date: 2020-11-19)
footnote Partial support
footnote The Atomics.waitAsync() method never times out. See bug 40742782.
Edge – Full support
Edge 90 (Release date: 2021-04-15)
footnote Full support
Firefox – Full support
Firefox 145 (Release date: 2025-11-11)
footnote Full support
Opera – Full support
Opera 75 (Release date: 2021-03-24)
footnote Full support
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Partial support
Chrome Android 89 – 89 (Release date: 2021-03-02)
footnote Partial support
footnote The Atomics.waitAsync() method never times out. See bug 40742782.
Chrome Android – Full support
Chrome Android 90 (Release date: 2021-04-13)
footnote Full support
Firefox for Android – Full support
Firefox for Android 145 (Release date: 2025-11-11)
footnote Full support
Opera Android – Partial support
Opera Android 63 – 63 (Release date: 2021-04-16)
footnote Partial support
footnote The Atomics.waitAsync() method never times out. See bug 40742782.
Opera Android – Full support
Opera Android 64 (Release date: 2021-05-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 15 (Release date: 2021-08-13)
footnote Full support
WebView Android – Partial support
WebView Android 89 – 89 (Release date: 2021-03-02)
footnote Partial support
footnote The Atomics.waitAsync() method never times out. See bug 40742782.
WebView Android – Full support
WebView Android 90 (Release date: 2021-04-13)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.4 (Release date: 2020-09-13)
footnote Full support
Node.js – Full support
Node.js 16 (Release date: 2021-04-20)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.

See also