Bluebird Promise Retry Utility

0.11.0 · maintenance · verified Sun Apr 19

bluebird-retry is a utility library for Node.js and browsers that facilitates retrying an asynchronous operation until it successfully resolves. It leverages Bluebird promises for its core functionality and expects Bluebird to be provided as a peer dependency. The current stable version is 0.11.0. This package supports various retry mechanisms including regular intervals, exponential backoff with configurable limits, and an overall operation timeout. A key differentiator is its ability to conditionally retry based on a `predicate` (similar to Bluebird's filtered catch) and to explicitly stop the retry loop by throwing a `StopError`. While functional, the package appears to be in maintenance mode, with its last release (v0.11.0) occurring several years ago, and is primarily designed for CommonJS environments.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `bluebird-retry` to repeatedly execute an asynchronous function until it returns a successful promise, configured with a maximum number of attempts and a fixed interval.

const Promise = require('bluebird');
const retry = require('bluebird-retry');

let count = 0;
function myfunc() {
    console.log('myfunc called ' + (++count) + ' times');
    if (count < 3) {
        // Simulate an asynchronous failure with a Bluebird rejection
        return Promise.reject(new Error('fail the first two times'));
    } else {
        // Simulate an asynchronous success
        return Promise.resolve('succeed the third time');
    }
}

retry(myfunc, { max_tries: 5, interval: 500 })
.then(function(result) {
    console.log(result);
})
.catch(function(err) {
    console.error('Operation failed completely:', err.message);
});

view raw JSON →