
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
promise-spin-wait
Advanced tools
An ES6-Promise based spin wait
$ npm install --save promise-spin-wait
Imagine you'd want to test a script that sends emails. Sadly the infrastructure that actually sends them is out of your controll, so emails are not delivered instantly. This is when a spin wait can be useful, it allows you to check regularly for a certain criteria until it's fulfilled.
const spinner = require('promise-spin-wait');
return sendEmail() // Asyncronous, but it will return before the email has actually been delivered
.then(() => {
return spinner(
() => {
return getEmailInboxCount().then(n => n > 0);
},
{
message: "Timeout: No Email received",
timeout: 5000,
interval: 500
}
);
})
Returns a promise for a the first truish response of fn() or the first rejected promise of fn();
A function returning a value or a promise. If a promise is returned fn() will not be called again until it is resolved. Any errors thrown or promise rejections will lead to the spinner rejecting as well.
Only a truish return value will lead to the spinner stopping.
Type: string
Default: Timeout
Message thrown when timeout occurs
Type: number
Default: 5000
Milliseconds since start when instead of calling fn again an timeout error will be returned
Type: number
Default: 100
Duration between the last time fn() has been fulfilled and the next fn() is being called
MIT © marekventur
FAQs
An ES6-Promise based spin wait
The npm package promise-spin-wait receives a total of 0 weekly downloads. As such, promise-spin-wait popularity was classified as not popular.
We found that promise-spin-wait 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.