New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

megaorm-echo

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

megaorm-echo

This package designed to provide robust retry mechanisms for your operations. It allows you to configure retry logic with customizable delay and incremental backoffs.

unpublished
latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

MegaORM Echo

This package designed to provide robust retry mechanisms for your operations, such as network requests or database queries. It allows you to configure retry logic with customizable delay and incremental backoffs.

Installation

Install the package using npm:

npm install megaorm-echo

Here’s an improved version of the Getting Started section for clarity, grammar, and conciseness:

Creating an Instance

To start using Echo, create an instance with optional configurations:

const { Echo } = require('megaorm-echo');

// Create an Echo instance with:
// - maxRetry: 10 (maximum retries)
// - retryDelay: 1000 ms (delay between retries)
// - extraDelay: 500 ms (incremental delay added after each retry)
const echo = new Echo(10, 1000, 500);

Retrying a Job

The retry method executes a job and retries it according to the configuration.

Example 1: Successful Job

const fetchSuccess = () => {
  return new Promise((resolve) => {
    setTimeout(() => resolve('Success'), 100);
  });
};

// Executes the job and resolves on the first attempt after 1000 ms.
echo.retry(fetchSuccess).then((result) => console.log(result)); // Output: Success

Example 2: Failing Job

const fetchFail = () => {
  return new Promise((_, reject) => {
    setTimeout(() => reject(new Error('Fail')), 100);
  });
};

// Retries the job 10 times before rejecting.
// - Each retry waits 1000 ms (10 seconds total for 10 retries).
// - An additional 500 ms is added incrementally after each retry.
echo.retry(fetchFail).catch((error) => console.log(error.message)); // Output: Fail

Setters

You can configure Echo using the following methods:

  • set.maxRetry(number): Sets the maximum number of retries. Must be an integer greater than 0.
  • set.retryDelay(number): Sets the delay (in milliseconds) between retries. Must be an integer greater than 0.
  • set.extraDelay(number): Adds an incremental delay (in milliseconds) after each retry. Must be an integer greater than or equal to 0.
echo.set.maxRetry(5); // Retry job 5 times
echo.set.retryDelay(1000); // After 1000 ms
echo.set.extraDelay(200); // Add 200 ms to 1000 ms before every retry attempt

Getters

Retrieve current configurations:

  • get.maxRetry(): Returns the current maxRetry value.
  • get.retryDelay(): Returns the current retryDelay value.
  • get.extraDelay(): Returns the current extraDelay value.
console.log(echo.get.maxRetry()); // 5
console.log(echo.get.retryDelay()); // 1000
console.log(echo.get.extraDelay()); // 200

API

Constructor

constructor(maxRetry: number = 3, retryDelay: number = 500, extraDelay: number = 0)

Initializes a new Echo instance.

  • maxRetry: Maximum number of retries. Default: 3.
  • retryDelay: Delay between retries (in milliseconds). Default: 500.
  • extraDelay: Additional delay added incrementally after each retry (in milliseconds). Default: 0.

Methods

retry<T>(job: () => T | Promise<T>): Promise<T>

Retries a given function or job for the configured number of attempts.

  • job: A regular function or async operation to retry.
  • Returns: A Promise that resolves with the result of the job or rejects with the error if all retries fail.

static sleep(delay: number): Promise<void>

Delays execution for the specified duration.

  • delay: Delay time in milliseconds.
  • Returns: A Promise that resolves after the delay.

set Methods

  • set.maxRetry(maxRetry: number): Sets the maximum number of retries.
  • set.retryDelay(retryDelay: number): Sets the delay between retries.
  • set.extraDelay(extraDelay: number): Sets the additional incremental delay.

get Methods

  • get.maxRetry(): Gets the current maxRetry value.
  • get.retryDelay(): Gets the current retryDelay value.
  • get.extraDelay(): Gets the current extraDelay value.

Keywords

megaorm-echo

FAQs

Package last updated on 16 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts