February 2018
Intermediate to advanced
298 pages
8h 22m
English
Atomics.add is a way to add a particular value to a particular index in a typed array. It is fairly simple to understand and write:
const sab = new SharedArrayBuffer(1);const arr = new Uint8Array(sab);arr[0] = 5;console.log(Atomics.add(arr, 0, 10));console.log(Atomics.load(arr, 0));
Atomics.add is, again, a thread-safe way of performing arr[0] += 10.
This outputs:
515
Read now
Unlock full access