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-retryVerified import paths — ran on the pinned version, not inferred.
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.
Ensure `bluebird` is installed in your project: `npm install bluebird` or `yarn add bluebird`.
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.
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.
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.
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.
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.
Ensure `bluebird` is installed (`npm install bluebird`) and imported at the top of your file: `const Promise = require('bluebird');`.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.