-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
What is the recommended approach for checking if a backoff is currently pending? I'm currently checking the if timeoutID_ !== -1 to determine if a backoff is currently pending. I'd rather not depend on an implementation detail like backoff.timeoutID_.
The following is my use case:
var Backoff = require('backoff');
var backoff = Backoff.exponential();
// if the browser goes online then let's reset the backoff
// to provide a better user experience when attempting to reconnect
window.addEventListener('online', function() {
// are we currently waiting to reconnect
const is_pending_backoff = backoff.timeoutID_ !== -1;
// reset the backoff
backoff.reset();
// since resetting the backoff will cancel a
// pending backoff lets go ahead and trigger
// a new backoff
if( is_pending_backoff ) {
backoff.backoff();
}
} );Maybe adding an isPending to the api is a good idea?
Backoff.prototype.isPending = function() {
return this.timeoutID_ != -1;
}Thanks for a great library!
Ryan
mikuhl-dev
Metadata
Metadata
Assignees
Labels
No labels