
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
wait-for-cond
Advanced tools
Returns a promise that resolves when a condition is met, and rejects when hitting a timeout
Wait until a condition is satisfied. Useful for testing.
$ npm i -S wait-for-cond
The promise resolves if the condition is met at least once in the specified duration, and rejects otherwise.
var waitFor = require('wait-for-cond');
var someCondition = true;
waitFor(function() {
return someCondition;
}, 2000, 'an optional reject message')
.then(function() {
console.log('condition is fulfilled.');
})
.catch(function() {
console.error('condition was not fulfilled in time.');
});
The condition result can also be wrapped in a promise.
var waitFor = require('wait-for-cond');
var someCondition = true;
waitFor(function() {
return new Promise(function(resolve) {
return resolve(someCondition);
});
}, 2000, 'an optional reject message')
.then(function() {
console.log('condition is fulfilled.');
})
.catch(function() {
console.error('condition was not fulfilled in time.');
});
waitFor.hold resolves if the condition remains satisfied for the entire duration, and rejects otherwise.
var waitFor = require('wait-for-cond');
var someCondition = true;
waitFor.hold(function() {
return new Promise(function(resolve) {
return someCondition;
});
}, 2000, 'an optional reject message')
.then(function() {
console.log('condition remained satisfied for 2000ms');
})
.catch(function() {
console.error('condition was unsatisfied during the 2000ms duration');
});
The promise resolves if the assertion was fulfilled at least once in the specified duration, and rejects otherwise.
var assert = require('assert');
var waitFor = require('wait-for-cond');
var someCondition = true;
waitFor.assert(function() {
assert(someCondition);
}, 2000)
.then(function() {
console.log('assertion succeeded in time.');
})
.catch(function() {
console.log('assertion did not succeed in time.');
});
The promise resolves if the assertion remains fulfilled for the entire specified duration, and rejects otherwise.
var assert = require('assert');
var waitFor = require('wait-for-cond');
var someCondition = true;
waitFor.assertHold(function() {
assert(someCondition);
}, 2000)
.then(function() {
console.log('assertion was held for the entire duration.');
})
.catch(function() {
console.log('assertion failed in the specified duration.');
});
FAQs
Returns a promise that resolves when a condition is met, and rejects when hitting a timeout
We found that wait-for-cond 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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.