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 (0)