Open In App

JavaScript Atomics notify() Method

The Atomics.notify() is an in-built method in JavaScript that is used to notify some agents that are sleeping in the wait queue. The Atomics.notify() method returns a number of woken-up agents. The integer-typed array, index, and count are passed as an argument to the function.

Syntax: 



Atomics.notify(typedArray, index, count)

Parameters: This method accepts three parameters as mentioned above and described below: 

Return value: The Atomics.notify() method returns the number of woken-up agents.



The below programs illustrate the Atomics.notify() method in JavaScript:

Example 1: In this example, we will see the use of the Atomics.notify() method in JavaScript.




<script>
    const sab = new SharedArrayBuffer(1024);
    const int32 = new Int32Array(sab);
    int32[0] = 77; 
    console.log(int32[0]);
    console.log(Atomics.store(int32, 0, 123)); 
    console.log(Atomics.notify(int32, 0, 1)); 
</script>

Output: 

77
123
0

Example 2: In this example, we will see the use of the Atomics.notify() method in JavaScript.




<script>
    const sab = new SharedArrayBuffer(1024);
    const int32 = new Int32Array(sab);
    int32[0] = 77; 
    console.log(Atomics.load(int32, 66));
    console.log(int32[0]);
    console.log(Atomics.store(int32, 0, 123)); 
    console.log(Atomics.notify(int32, 6, 1));
    console.log(int32[0]);
</script>

Output: 

0
77
123
0
123

Exceptions: 

We have a complete list of Javascript Atomics methods, to check those please go through the Javascript Atomics Complete Reference article.

Supported Browser:


Article Tags :