JavaScript Atomics waitAsync() Method

Beginner
7 min read
Updated: Nov 2026
3 examples
Atomics

Definition

Atomics.waitAsync(typedArray, index, value, timeout) is the non-blocking version of Atomics.wait(). Instead of putting the thread to sleep, it returns an object right away: { async, value }. If no waiting is needed, async is false and value is already the answer, "not-equal" or "timed-out". Otherwise async is true and value is a promise that resolves to "ok" when Atomics.notify() is called on the element, or "timed-out" after timeout milliseconds. Because nothing blocks, it may be used on the browser main thread. It is newer than wait() (ES2024) and not yet in every browser, so feature-detect it.

Remember
Atomics.waitAsync(typedArray, index, value)            -> { async, value }
Atomics.waitAsync(typedArray, index, value, timeout)

{ async: false, value: "not-equal" }    value already different
{ async: false, value: "timed-out" }    timeout 0, nothing to wait for
{ async: true,  value: Promise }        resolves "ok" or "timed-out"

never blocks: fine on the browser main thread
feature-detect: typeof Atomics.waitAsync === "function"

Syntax

The arguments are the same as for Atomics.wait(); the difference is the result object.

JavaScript
Atomics.waitAsync(typedArray, index, value)
Atomics.waitAsync(typedArray, index, value, timeout)
CallWhat it does
Atomics.waitAsync(typedArray, index, value)Returns { async: true, value: promise } while the element equals value; the promise resolves to "ok" on notify. Returns { async: false, value: "not-equal" } otherwise.
Atomics.waitAsync(typedArray, index, value, timeout)The same, but the promise resolves to "timed-out" after timeout ms. A timeout of 0 gives { async: false, value: "timed-out" } immediately.

Added in ES2024. Chromium-based browsers have had it the longest; other engines added it later, so check typeof Atomics.waitAsync === "function" before using it. Node.js 24 supports it.

Library declarations
JavaScript
Atomics.waitAsync(typedArray, index, value, timeout)
// returns { async: false, value: "not-equal" | "timed-out" }
//      or { async: true,  value: Promise<"ok" | "timed-out"> }

// typedArray: Int32Array or BigInt64Array on a SharedArrayBuffer
// timeout:    milliseconds, default Infinity

Parameters

ParameterDescription
typedArrayRequired. An Int32Array or BigInt64Array on a SharedArrayBuffer. A normal buffer or another element type throws a TypeError, exactly as with wait().
indexRequired. The element to watch. An invalid position throws a RangeError.
valueRequired. The value that means “keep waiting”. If the element is already different, the result is "not-equal" straight away. Use a BigInt with a BigInt64Array.
timeoutOptional. Milliseconds before the promise gives up with "timed-out". The default is Infinity.

Return Value

Return ValueDescription
{ async: false, value }No waiting was needed: value is the string "not-equal" or "timed-out".
{ async: true, value }value is a promise that resolves to "ok" (notified) or "timed-out".

JavaScript Examples

Example 1 — When the Answer Is Ready at Once

If the value already changed, or the timeout is 0, waitAsync() answers immediately with async: false.

JavaScript
const shared = new Int32Array(new SharedArrayBuffer(8));
Atomics.store(shared, 0, 7);

const changed = Atomics.waitAsync(shared, 0, 0);
console.log(changed.async);    // false
console.log(changed.value);    // not-equal

const noWait = Atomics.waitAsync(shared, 1, 0, 0);
console.log(noWait.async);     // false
console.log(noWait.value);     // timed-out
Try It Yourself

This example needs SharedArrayBuffer and Atomics.waitAsync(). A normal browser tab is not cross-origin isolated, so the Try It page prints a short explanation and the output above. On a cross-origin isolated page it runs the code for real.

How It Works

  1. A different value ends it early. Slot 0 holds 7, not 0, so there is nothing to wait for: async is false and value is "not-equal".
  2. A zero timeout ends it too. Slot 1 does hold 0, but with a timeout of 0 the call gives up at once with "timed-out".
  3. No promise was created. In both cases value is a plain string, which is why you read async first.

Example 2 — The Promise Resolves With "ok"

The value matches, so waitAsync() returns a pending promise. A notify() on the same slot settles it with "ok".

JavaScript
const shared = new Int32Array(new SharedArrayBuffer(4));
const result = Atomics.waitAsync(shared, 0, 0, 1000);

console.log(result.async);           // true
console.log(typeof result.value);    // object
result.value.then(function (outcome) {
  console.log("promise says: " + outcome);
});
console.log("woken: " + Atomics.notify(shared, 0));
Try It Yourself

This example needs SharedArrayBuffer and Atomics.waitAsync(). A normal browser tab is not cross-origin isolated, so the Try It page prints a short explanation and the output above. On a cross-origin isolated page it runs the code for real.

How It Works

  1. A real wait begins. Slot 0 is 0 as expected, so async is true and value is a promise (typeof says "object").
  2. notify() counts the promise. A pending waitAsync() counts as a waiter, so notify() returns 1.
  3. The callback runs afterwards. then() callbacks run after the current code finishes, so promise says: ok is printed last.

Example 3 — Await the Result, With a Timeout

An async function handles both shapes of the result and waits at most 10 ms. Nobody notifies, so the outcome is "timed-out".

JavaScript
const shared = new Int32Array(new SharedArrayBuffer(4));
const keepAlive = setTimeout(function () {}, 1000);   // Node.js would exit early without it

async function waitForSignal() {
  const result = Atomics.waitAsync(shared, 0, 0, 10);
  console.log("waiting: " + result.async);
  const outcome = result.async ? await result.value : result.value;
  console.log("outcome: " + outcome);
  clearTimeout(keepAlive);
}

waitForSignal();
Try It Yourself

This example needs SharedArrayBuffer and Atomics.waitAsync(). A normal browser tab is not cross-origin isolated, so the Try It page prints a short explanation and the output above. On a cross-origin isolated page it runs the code for real.

How It Works

  1. Handle both result shapes. The conditional result.async ? await result.value : result.value works whether you got a promise or a ready string.
  2. Ten quiet milliseconds. No thread calls notify(), so after 10 ms the promise resolves to "timed-out", and the page stays responsive the whole time.
  3. Keep Node.js running. A pending waitAsync() timer does not keep Node.js alive, so the empty setTimeout holds the program open until the outcome is printed. Browsers do not need it.

Browser & Runtime Support

Atomics.waitAsync() was added in ES2024. Chromium-based browsers shipped it first; other engines followed later. It also needs SharedArrayBuffer.

✓ ES2024 · feature-detect

Atomics.waitAsync()

Available in Chrome, Edge, and other Chromium browsers and in Node.js (checked on version 24). Check other browsers before relying on it, and serve the page cross-origin isolated.

Most Not yet in every engine
Google Chrome Supported for several years · needs cross-origin isolation
Supported
Microsoft Edge Supported (Chromium) · needs cross-origin isolation
Supported
Opera Supported (Chromium) · needs cross-origin isolation
Supported
Apple Safari Added later than Chromium · needs cross-origin isolation
Check version
Mozilla Firefox Added later than Chromium · needs cross-origin isolation
Check version
Samsung Internet Depends on the Chromium base · needs cross-origin isolation
Check version
Internet Explorer No Atomics object
Not supported
Node.js Current releases · checked on Node 24
Supported
Deno Recent releases
Check version
Bun Recent releases
Check version
Atomics.waitAsync() Check your targets

Bottom line: Feature-detect with typeof Atomics.waitAsync === "function". Where it is missing, wait inside a Worker with Atomics.wait() and send the result back with postMessage().

Frequently Asked Questions

An object with two properties. If async is false, value is already "not-equal" or "timed-out". If async is true, value is a promise that resolves to "ok" or "timed-out".
wait() blocks the thread and returns a string. waitAsync() returns at once and gives you a promise for the outcome, so it can be used on the browser main thread.
No. Like wait(), it needs an Int32Array or BigInt64Array on a SharedArrayBuffer and throws a TypeError otherwise. In browsers that means a cross-origin isolated page.
A pending waitAsync() timeout does not keep the Node.js event loop alive. Keep the process busy, for example with a timer or a worker, until the promise resolves.
Test typeof Atomics.waitAsync === "function". It is an ES2024 addition and not every browser version has it.

Next: Atomics.xor()

Toggle flags on and off with a bitwise XOR.

xor() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful