Skip to content

is backoff pending? #18

@DetweilerRyan

Description

@DetweilerRyan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions