notify-then-sleep-or.ts 347 B

12345678910
  1. // Set the index-th bith in i32array[0], then wait for it to be un-set again.
  2. module.exports = function ({ i32array, index }) {
  3. Atomics.or(i32array, 0, 1 << index);
  4. Atomics.notify(i32array, 0, Infinity);
  5. do {
  6. const v = Atomics.load(i32array, 0);
  7. if (!(v & (1 << index))) break;
  8. Atomics.wait(i32array, 0, v);
  9. } while (true);
  10. };