Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yveskaufmann/retry

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yveskaufmann/retry - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

.nvmrc

16

dist/retry.d.ts

@@ -23,2 +23,6 @@ /**

/**
* The max number of milliseconds between two retries. Default is `Unlimited`
*/
maxDelay?: number;
/**
* Defines the condition on which a operation should be retried a implementation

@@ -35,2 +39,12 @@ * should return true if a retry is desired.

/**
* Will be invoked after each failed attempt.
* An atempt is to be considered failed, if the `retryWhen` classify a returned error/return-values as retryable.
* @param attempt The number of the attempt
* @param result The returned value from the retryable operation, that is considered be a reason to perform a retry
* @param err The cause of the failed attempt
* @returns
*/
onFailedAttempt?: (attempt: number, result: T, err: Error) => void;
/**
* Calculates the delay between retries in milliseconds.

@@ -110,3 +124,3 @@ *

*/
static do<T>({ operation, retryWhen: retryCondition, maxRetries, delay, throwMaxAttemptError, nameOfOperation, }: {
static do<T>({ operation, retryWhen: retryCondition, maxRetries, delay, throwMaxAttemptError, nameOfOperation, maxDelay, onFailedAttempt, }: {
operation: () => Promise<T>;

@@ -113,0 +127,0 @@ } & RetryOptions<T>): Promise<T>;

10

dist/retry.js

@@ -85,3 +85,3 @@ "use strict";

*/
static do({ operation, retryWhen: retryCondition, maxRetries, delay, throwMaxAttemptError, nameOfOperation, }) {
static do({ operation, retryWhen: retryCondition, maxRetries, delay, throwMaxAttemptError, nameOfOperation, maxDelay, onFailedAttempt, }) {
return __awaiter(this, void 0, void 0, function* () {

@@ -107,6 +107,12 @@ maxRetries = maxRetries !== null && maxRetries !== void 0 ? maxRetries : 2;

}
if (typeof onFailedAttempt === 'function') {
onFailedAttempt(attempts + 1, result, previousError);
}
attemptsLeft = attempts++ < maxRetries;
shouldRetry = shouldRetry && attemptsLeft;
if (shouldRetry) {
const delayDuration = delay(attempts, previousError);
let delayDuration = delay(attempts, previousError);
if (typeof maxDelay === 'number' && maxDelay > 0) {
delayDuration = Math.min(maxDelay, delayDuration);
}
yield (0, wait_1.wait)(delayDuration);

@@ -113,0 +119,0 @@ }

{
"name": "@yveskaufmann/retry",
"version": "1.0.1",
"version": "1.1.0",
"description": "Utility for retrying promise based operation on certain situations.",

@@ -33,15 +33,15 @@ "main": "dist/index.js",

"@types/jest": "^27.4.1",
"@types/node": "^16.11.26",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-unicorn": "^35.0.0",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "~5.52.0",
"@typescript-eslint/parser": "~5.52.0",
"eslint": "~8.34.0",
"eslint-config-prettier": "~8.6.0",
"eslint-plugin-import": "~2.27.5",
"eslint-plugin-jest": "~27.2.1",
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-unicorn": "~45.0.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
"typescript": "^4.9.5"
}
}

@@ -68,8 +68,12 @@ # @yveskaufmann/retry - retry-utility

- [RetryOptions](#retryoptions)
- [Retry](#retry)
- [Retry#Delays](#retrydelays)
- [Retry#Conditions](#retryconditions)
- [Retryable](#retryable)
- [MaxRetryAttemptsReached](#maxretryattemptsreached)
- [@yveskaufmann/retry - retry-utility](#yveskaufmannretry---retry-utility)
- [Installation](#installation)
- [Usage](#usage)
- [API Reference](#api-reference)
- [RetryOptions](#retryoptions)
- [Retry](#retry)
- [RetryDelays](#retrydelays)
- [RetryConditions](#retryconditions)
- [Retryable](#retryable)
- [MaxRetryAttemptsReached](#maxretryattemptsreached)

@@ -106,2 +110,7 @@ ### RetryOptions

/**
* The max number of milliseconds between two retries. Default is `Unlimited`
*/
maxDelay?: number;
/**
* Defines the condition on which a operation should be

@@ -133,2 +142,13 @@ * retried, a implementation should return true

delay?: (attempts: number, error?: Error) => number;
/**
* Will be invoked after each failed attempt.
* An atempt is to be considered failed, if the `retryWhen` classify a returned error/return-values as retryable.
* @param attempt The number of the attempt
* @param result The returned value from the retryable operation, that is considered be a reason to perform a retry
* @param err The cause of the failed attempt
* @returns
*/
onFailedAttempt?: (attempt: number, result: T, err: Error) => void;
}

@@ -135,0 +155,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc