Effortless JavaScript Retries with redo.js! 🚀
Tired of handling unreliable APIs, flaky database queries, or network failures? Instead of writing complex retry logic, let redo.js handle it for you—simple, powerful, and effortless!
Why redo.js?
✅ Works with Node.js, React, Vue, and more✅ Supports customizable retry strategies (exponential backoff, fixed delays, etc.)✅ Handles errors automatically with minimal code
📦 Installation
- Using npm:
npm install redo.js
- Using yarn:
yarn add redo.js
⚡ Usage
🔄 Retry Synchronous Operations
import { retryOperation } from "redo.js";
retryOperation({
retryCount: 3, // Default: 3 - Number of retry attempts
retryDelay: 1000, // Default: 1000ms - Delay between retries
// incrementalDelayFactor: 2, // Optional - Exponential backoff factor
retryCallback: () => {
console.log("Retrying operation...");
throw new Error("Operation failed");
},
onErrorCallback: () => console.log("An error occurred."),
onSuccessCallback: () => console.log("Operation succeeded!"),
afterLastAttemptErrorCallback: (error) =>
console.error("Final error:", error.message),
});
🔄 Retry Asynchronous Operations
import axios from "axios";
import { retryAsyncOperation } from "redo.js";
const fetchData = async () => {
return axios.get("https://jsonplaceholder.typicode.com/posts");
};
retryAsyncOperation({
retryCount: 3,
retryDelay: 1000,
// incrementalDelayFactor: 2,
retryAsyncCallback: async () => await fetchData(),
onErrorCallback: (error, currentRetryCount) =>
console.log(`Retry #${currentRetryCount} failed: ${error.message}`),
onSuccessCallback: (response) =>
console.log("Operation succeeded with status:", response.status),
afterLastAttemptErrorCallback: (error) =>
console.error("Final error:", error.message),
});
🚀 Try redo.js today and make your async workflows resilient!
🔄 Like, share, and support! 😊
Thank you! 🙌
Top comments (2)
Without using any libraries: github.com/vitaly-t/retry-async
Nice idea :-)
Is the source code available?
Curious about the implementation details.
Does
retryAsyncOperation
return aPromise
so that it can be awaited?It feels like it should... but then
onSuccessCallback
andafterLastAttemptErrorCallback
would be superfluous.