alonmiz / poll-until-promise Goto Github PK
View Code? Open in Web Editor NEWRetry until a promise succeeds
Retry until a promise succeeds
Hi,
Would you accept a PR for a new option like maxBackoffInterval
? For example, if you specified interval
= 1, backoffFactor
= 2, and maxBackoffInterval
= 10, you'll get retries at 1, 2, 4, 8, 10, 10, 10, 10, 10, ... and so on until success or timeout reached.
Backoff retry is obviously great but growing without bound is probably not wanted in practice.
Thanks!
For example, if you use backoffFactor
= 2 and interval
= 1000, the first retry will take place after 2000ms. I would expect the first retry to take place after 1000ms and the second retry to take place after 2000ms.
If that is intentional, a usage note in the docs would be nice.
const { waitFor } = require('poll-until-promise');
function A() {
return waitFor(() => {
if (Math.random() >= 0.5) {
throw new Error('try again');
} else {
console.log('all good')
}
})
}
async function B() {
await A()
}
this will not give stacktrace of B
Hi @AlonMiz,
Curious if you'd be interested in a PR for the following:
maxAttempts
-- Sometimes, the semantics of "attempt this operation X times" are preferable over "attempt this operation until X time has passed". You could get close to this behavior by setting timeout = interval * numDesiredAttempts
, but it's not exact/guaranteed and it also gets more complicated if you're using a backoffFactor
or similar. Note that this option is additive and wouldn't replace the timeout
; if maxAttempts
is passed, then polling stops when either the timeout is reached OR attempts are exhausted.
fail-fast when stopOnFailure===false
-- The stopOnFailure
setting is all-or-nothing; that is, either ANY error will stop the loop, or no errors will. It would be nice to have some dedicated error that could be conditioned to stop the loop even when stopOnFailure
is false.
// Usage in execution function:
throw new AbortError(myError); // <--- stops polling immediately, myError is reported
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.