Nonlinear Performance Magnification
Miss any of our Open RFC calls?Watch the recordings here! »

wait-notify

1.0.3 • Public • Published

wait-notify

Wait here until others notify you that you can go!

Just support node now.

Introduction

Wait/Notify mode like other languages.

Installation

$ npm install wait-notify [--save]

Examples

test.js

const WaitNotify = require('wait-notify');
const waitNotify = new WaitNotify();

(async () => {
    setInterval(() => {
        waitNotify.notify();
    }, 1000);
})();

(async () => {
    let count = 10;
    while (count > 0) {
      try {
        await waitNotify.wait();
      } catch (e) {
        console.log(e);
      }
      count--;
      console.log('wait notify count', count);
    }
})();

API

WaitNotify()

the constructor

WaitNotify.wait(timeout=0)

wait until others notify or timeout

  • timeout : integer The max time to wait in millisecond. default is infinite.
  • return : promise Wait the end, or catch the timeout error

WaitNotify.notify()

notify all the waiter to wake up

  • return : undefined

WaitNotify.notifyAll()

notify all the waiter to wake up

  • return : undefined

WaitNotify.notifyOne()

notify the first waiter to wake up

  • return : undefined

License

The project is licensed under the MIT License. See the LICENSE file for more details

Install

npm i wait-notify

DownloadsWeekly Downloads

84

Version

1.0.3

License

MIT

Unpacked Size

5.67 kB

Total Files

6

Last publish

Collaborators

  • avatar