Atomics.notify(typedArray, index, count) wakes up threads that are sleeping in Atomics.wait(), or waiting through Atomics.waitAsync(), on the same element. It wakes at most count of them (all of them by default), oldest waiter first, and returns the number it actually woke. It never blocks, so it is allowed everywhere, including the browser main thread. If nobody is waiting, or the array is not shared at all, it simply returns 0. The usual order is: change the value first, then notify.
Remember
Atomics.notify(typedArray, index) -> number woken (all waiters)
Atomics.notify(typedArray, index, count) -> number woken (at most count)
nobody waiting -> 0
not a shared array -> 0
store the new value first, then notify
Int32Array or BigInt64Array only
Syntax
Call it with or without a limit on how many waiters to wake.
Wakes every thread waiting on typedArray[index] and returns how many there were.
Atomics.notify(typedArray, index, count)
Wakes at most count waiters, in the order they started waiting. count 1 is the classic “wake one worker” call.
Part of JavaScript since ES2017. Early drafts called it Atomics.wake(); that name is gone, so always use notify().
Library declarations
JavaScript
Atomics.notify(typedArray, index, count) // returns the number woken
// typedArray: Int32Array or BigInt64Array (shared or not)
// count: default Infinity; negative counts act like 0
// unshared array -> always returns 0
Parameters
Parameter
Description
typedArray
Required. An Int32Array or BigInt64Array. Other types (even Uint32Array) throw a TypeError. On a normal ArrayBuffer the call is allowed but always returns 0.
index
Required. The element the waiters are sleeping on. An invalid position throws a RangeError.
count
Optional. The most waiters to wake. The default is Infinity (wake all). 0 or a negative number wakes nobody.
Return Value
Return Value
Description
Number
How many waiting threads (or pending waitAsync() promises) were woken: from 0 up to count.
JavaScript Examples
Example 1 — When notify() Returns 0
On a normal, unshared Int32Array nobody can be waiting, so notify() returns 0. This one runs in any browser tab.
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
Three waiters line up. Each waitAsync() call returns a pending promise, and the engine queues the waiters in order.
count limits the wake-up.notify(shared, 0, 1) wakes exactly one waiter and returns 1; the next call without count wakes the other 2.
A third call finds nobody. The queue is empty, so it returns 0. All three promises have resolved with "ok".
Example 3 — The Safe Pattern: Store, Then Notify
A Node.js worker sleeps in a loop until a flag becomes 1. The main thread stores the flag first and notifies second, so the wake-up can never be missed, whatever the timing.
JavaScript
const { Worker } = require("worker_threads");
const flag = new Int32Array(new SharedArrayBuffer(4));
const worker = new Worker(
"const { parentPort, workerData } = require('worker_threads');" +
"while (Atomics.load(workerData, 0) === 0) Atomics.wait(workerData, 0, 0);" +
"parentPort.postMessage('worker sees flag = ' + Atomics.load(workerData, 0));",
{ eval: true, workerData: flag }
);
worker.on("message", function (text) {
console.log(text);
worker.terminate();
});
Atomics.store(flag, 0, 1);
Atomics.notify(flag, 0);
console.log("main: flag stored and notify sent");
main: flag stored and notify sent
worker sees flag = 1
The code above uses Node.js worker_threads. The Try It page runs the same steps with a browser Worker made from a Blob URL. It needs SharedArrayBuffer, so in a normal (not cross-origin isolated) tab it prints a short explanation and the output above.
How It Works
The worker checks before sleeping. Its loop only calls wait() while the flag is 0, and checks again after every wake-up.
Main stores, then notifies. If the worker is already asleep, notify() wakes it. If it has not started yet, it will see the 1 and never sleep. Either way nothing is lost.
The order of output is fixed. The main thread prints first, because the worker’s message can only be handled after the main script finishes. The count notify() returns (0 or 1) depends on timing, so it is not printed.
Compatibility
Browser & Runtime Support
Atomics.notify() is an ES2017 method. It never blocks, so it is allowed on the browser main thread as well as in workers.
✓ Baseline · ES2017
Atomics.notify()
Supported in all modern browsers and in Node.js, Deno, and Bun. Waking another thread needs a SharedArrayBuffer, and browsers provide that only on cross-origin isolated pages.
95%Modern browser support
Google ChromeModern versions · sharing needs cross-origin isolation
Full support
Mozilla FirefoxModern versions · sharing needs cross-origin isolation
Full support
Apple SafariModern versions · sharing needs cross-origin isolation
Full support
Microsoft EdgeModern versions · sharing needs cross-origin isolation
Bottom line: You can call notify() anywhere. In a normal browser tab there is no SharedArrayBuffer, so there is nobody to wake and it returns 0. Serve the page with COOP and COEP headers to share memory with workers.
Frequently Asked Questions
The number of waiters it woke up, from 0 to count. It counts both threads sleeping in Atomics.wait() and pending Atomics.waitAsync() promises.
Either nobody was waiting on that element at that moment, or the typed array is not backed by a SharedArrayBuffer, in which case nobody can ever be waiting.
Yes. Unlike Atomics.wait(), notify() never blocks, so the main thread may call it to wake workers.
It limits how many waiters are woken. The default is Infinity (all of them); Atomics.notify(a, i, 1) wakes just the oldest waiter.
No. A notify with no sleepers does nothing. That is why you store the new value first and let the waiter check the value before and after it sleeps.