Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
await-notify
Advanced tools
Simple library providing Java like wait and notify functionality for async/await syntax.
Works in Node (or browser via Browserify or Webpack) when Promise and async/await syntax are enabled.
npm install --save await-notify
const { Subject } = require('await-notify');
const event = new Subject();
(async () => {
while (true) {
await event.wait();
console.log('Event occured');
}
})();
setTimeout(() => {
event.notify();
}, 1000);
A class representing subjects that could be waited for and notfied on.
Returns a promise that will be resolved either when the subject is been notfied or when timeout occurs.
timeout
parameter is in milliseconds, and no timeout will occur if not set to an finite number greater than 0.
The promise resolves false
if timeout occurs, resolves true
otherwise.
const subject = new Subject();
(async () => {
const notTimeout = await subject.wait();
...
})();
Resolve one waiting session. Does nothing if no one is waiting on this subject.
Return nothing and thus should not be used with await
.
subject.notify();
Similar to notify
but notifies all waiting session.
There's no fancy way to do this, but a Subject instance is just another plain JavaScript object which you can freely assign parameters to. So you may just do this:
const { Subject } = require('await-notify');
const event = new Subject();
(async () => {
while (true) {
await event.wait();
console.log('Event occured with message:'. event.message);
}
})();
setTimeout(() => {
event.message = 'Hello there';
event.notify();
}, 1000);
Under the hood, async/await are just sugar syntax for using Promise. So using promise directly is fine.
const { Subject } = require('await-notify');
const event = new Subject();
function listen() {
event.wait().then(() => {
console.log('Event occured');
listen();
});
}
listen();
setTimeout(() => {
event.message = 'Hello there';
event.notify();
}, 1000);
FAQs
Java like wait and notify for JavaScript ES7 async/await
The npm package await-notify receives a total of 2,567 weekly downloads. As such, await-notify popularity was classified as popular.
We found that await-notify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.