Registry / http-networking / bluebird-retry

bluebird-retry

JSON →
library0.11.0jsnpmunverified

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.

npm install bluebird-retry
INSTALL
IMPORT
SIG · BLUEBIRD-RETRY
B
bluebird-retry
http-networkingjavascriptv0.11.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

retry
const retry = require('bluebird-retry');
import retry from 'bluebird-retry';
Primarily designed for CommonJS; direct ESM import might not work without bundler configuration. The `retry` function is the main export.
retry.StopError
const retry = require('bluebird-retry'); // ... then later ... throw new retry.StopError('message');
import { StopError } from 'bluebird-retry';
StopError is a property of the main `retry` export, not a named export. It's used to gracefully exit the retry loop.
Promise (from bluebird)
const Promise = require('bluebird');
import { Promise } from 'bluebird';
bluebird-retry depends on Bluebird. If your operation uses `Promise.resolve` or `Promise.reject`, you must ensure Bluebird is imported and available, especially in older CJS contexts. Bluebird also has an ESM export, but CJS `require` is typical for older patterns.

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); });
Debug
Known issues
breakingThe `bluebird` library was changed from a direct dependency to a peer dependency. Applications must now explicitly install `bluebird` alongside `bluebird-retry`.
fix
Ensure `bluebird` is installed in your project: `npm install bluebird` or `yarn add bluebird`.
affects: >=0.6.0
gotchaThe `timeout` option does not create a real-time timeout, but rather computes a maximum number of attempts based on the `interval` and `backoff` options. If both `timeout` and `max_tries` are specified, the limit that comes first will apply.
fix
Understand that `timeout` is an estimation for `max_tries`. For strict time limits, consider wrapping `bluebird-retry` with a separate Bluebird `Promise.delay` and `Promise.race` if fine-grained control is critical.
affects: >=0.1.0
gotchaBy default, `bluebird-retry` absorbs all intermediate rejection messages, and will only propagate the final error if the operation ultimately times out or reaches `max_tries`. This can make debugging initial failures difficult.
fix
To throw the last encountered error instance instead of a timeout error, set the `throw_original` option to `true`. Alternatively, use the `predicate` option to filter which errors cause a retry.
affects: >=0.1.0
deprecatedThe package uses `.try` and `.catch` aliases (`.attempt` and `.caught` respectively) for older browser support. While functionally equivalent in Bluebird, modern Bluebird versions and native Promises prefer `.try` (or direct `try/catch` with `async/await`) and `.catch`.
fix
No direct fix needed as it's an internal implementation detail, but be aware that if you're writing new code, using standard Bluebird or native promise methods is generally preferred.
affects: >=0.6.0
gotchaAs a package in maintenance mode (last update several years ago), it may not fully leverage modern JavaScript features like `async/await` directly without explicit Bluebird promisification, nor is it optimized for ESM environments without transpilation or bundler configuration.
fix
For new applications, consider using native `async/await` with a custom retry loop or a more modern retry library that explicitly supports `async/await` and ESM. If using `bluebird-retry`, stick to its documented CommonJS usage.
affects: >=0.1.0
Errors
Common errors & fixes
Error: operation timed out
The retry operation exhausted its maximum number of attempts (`max_tries`) or exceeded its calculated `timeout` duration before the wrapped function succeeded.
fix
Increase the `max_tries` option, or adjust `interval` and `backoff` to allow more attempts within the `timeout` period. Alternatively, debug the underlying function to understand why it's consistently failing and fix it.
Promise is not defined
The `bluebird` library, which `bluebird-retry` depends on, has not been properly imported or is not available in the global scope/module context.
fix
Ensure `bluebird` is installed (`npm install bluebird`) and imported at the top of your file: `const Promise = require('bluebird');`.
TypeError: retry.StopError is not a constructor
You are attempting to use `retry.StopError` but `retry` was not correctly imported or is not the object containing the `StopError` class.
fix
Ensure you are importing `bluebird-retry` using `const retry = require('bluebird-retry');` and then referencing `retry.StopError` correctly. Do not try to destructure `StopError` directly from the package import.
Upgrade
Version history
0.11.0latest on npm
Audit
Dependencies
bluebirdrequiredProvides the underlying promise implementation; required as a peer dependency since v0.6.0.
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources