JavaScript Atomics notify() Method

Beginner
7 min read
Updated: Nov 2026
3 examples
Atomics

Definition

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.

JavaScript
Atomics.notify(typedArray, index)
Atomics.notify(typedArray, index, count)
CallWhat it does
Atomics.notify(typedArray, index)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

ParameterDescription
typedArrayRequired. An Int32Array or BigInt64Array. Other types (even Uint32Array) throw a TypeError. On a normal ArrayBuffer the call is allowed but always returns 0.
indexRequired. The element the waiters are sleeping on. An invalid position throws a RangeError.
countOptional. The most waiters to wake. The default is Infinity (wake all). 0 or a negative number wakes nobody.

Return Value

Return ValueDescription
NumberHow 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.

JavaScript
const plain = new Int32Array(4);   // normal memory, not shared

console.log(Atomics.notify(plain, 0));      // 0
console.log(Atomics.notify(plain, 1, 5));   // 0

try {
  Atomics.notify(new Uint8Array(4), 0);
} catch (e) {
  console.log(e.name);                      // TypeError
}
Try It Yourself

How It Works

  1. No sharing, no sleepers. Only a shared array can have waiters, so notify() on a normal one is allowed but wakes 0.
  2. count does not change that. Asking to wake up to 5 threads still wakes 0 when none are waiting.
  3. The type check still applies. A Uint8Array can never be waited on, so notify() rejects it with a TypeError.

Example 2 — Use count to Wake Waiters in Steps

Three waitAsync() promises wait on the same slot. notify() with count 1 wakes one, a second call wakes the remaining two.

JavaScript
const shared = new Int32Array(new SharedArrayBuffer(4));
const waiters = [1, 2, 3].map(function () {
  return Atomics.waitAsync(shared, 0, 0).value;
});

console.log(Atomics.notify(shared, 0, 1));   // 1
console.log(Atomics.notify(shared, 0));      // 2
console.log(Atomics.notify(shared, 0));      // 0

Promise.all(waiters).then(function (results) {
  console.log(results.join(", "));           // ok, ok, ok
});
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. Three waiters line up. Each waitAsync() call returns a pending promise, and the engine queues the waiters in order.
  2. 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.
  3. 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");
Try It Yourself

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

  1. The worker checks before sleeping. Its loop only calls wait() while the flag is 0, and checks again after every wake-up.
  2. 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.
  3. 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.

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 Chrome Modern versions · sharing needs cross-origin isolation
Full support
Mozilla Firefox Modern versions · sharing needs cross-origin isolation
Full support
Apple Safari Modern versions · sharing needs cross-origin isolation
Full support
Microsoft Edge Modern versions · sharing needs cross-origin isolation
Full support
Opera Modern versions · sharing needs cross-origin isolation
Full support
Samsung Internet Modern versions · sharing needs cross-origin isolation
Full support
Internet Explorer No Atomics object
Not supported
Node.js Current releases · checked on Node 24
Supported
Deno Current releases
Supported
Bun Current releases
Supported
Atomics.notify() Excellent

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.

Next: Atomics.or()

Switch flags on with a bitwise OR that never disturbs the other flags.

or() 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