Atomics.waitAsync()
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.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 90 | 90 | 145 | 16.4 | 90 | 16.4 | |
- This browser only partially implements this feature
- This feature was removed in a later browser version (90)
- The `Atomics.waitAsync()` method never times out. See bug 40742782.
- This browser only partially implements this feature
- This feature was removed in a later browser version (90)
- The `Atomics.waitAsync()` method never times out. See bug 40742782.
- This browser only partially implements this feature
- This feature was removed in a later browser version (90)
- The `Atomics.waitAsync()` method never times out. See bug 40742782.
Syntax
const sab = new SharedArrayBuffer(4);
const int32 = new Int32Array(sab);
const { async: waitPromise } = Atomics.waitAsync(int32, 0, 0);
waitPromise.then(() => console.log('The value has been changed')); Live demo
Check Atomics.waitAsync support
Inspect the availability of the async waiting API.
Start an async wait
Create the shared memory setup and inspect the returned wait token.
Resolve a waitAsync promise
Wake the waiting promise with Atomics.notify after updating the value.
Use cases
-
Async coordination
Wait for shared-memory state changes without freezing the thread that requested the wait.
-
Worker orchestration
Build advanced scheduling logic across workers while preserving non-blocking behavior.
Cautions
- This remains low-level concurrency code, so use it only when simpler async primitives are insufficient.
- Debugging async shared-memory coordination is still complex and requires disciplined testing.
Accessibility
- Better non-blocking behavior can help keep the UI responsive when background processing is heavy.
- Users still need visible progress and recovery states when concurrency-backed work takes time.