wait-notify
Version:
Wait here until others notify you that you can go!
65 lines (50 loc) • 1.44 kB
Markdown
Wait here until others notify you that you can go!
Just support node now.
Wait/Notify mode like other languages.
```sh
$ npm install wait-notify [--save]
```
[](https://github.com/machenjie/wait-notify/blob/master/test/index.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);
}
})();
```
the constructor
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
notify all the waiter to wake up
- `return` : undefined
notify all the waiter to wake up
- `return` : undefined
notify the first waiter to wake up
- `return` : undefined
The project is licensed under the MIT License. See the [LICENSE](https://github.com/machenjie/wait-notify/blob/master/LICENSE) file for more details