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

retry-machine

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retry-machine - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

11

lib/index.js

@@ -1,3 +0,6 @@

"use strict";
'use strict';
const nullLogger = require('null-logger');
const wait = ms => new Promise(resolve => setTimeout(() => {

@@ -9,9 +12,11 @@ resolve();

function retry({ max = 3, delay = 1000, factor = 1 } = {}, failure = async () => {}) {
return async function (promise, ...args) {
function retry({ max = 3, delay = 1000, factor = 1, logger = nullLogger } = {}, failure = async () => {}) {
return async function closure(promise, ...args) {
let attempts = max || 3;
let result = null;
/* eslint-disable no-await-in-loop */
while (attempts > 0) {
try {
logger.info('Retry Machine: ', ...args);
result = await promise(...args);

@@ -18,0 +23,0 @@ break;

{
"name": "retry-machine",
"version": "0.1.0",
"version": "0.2.0",
"description": "Retry Promises",

@@ -24,2 +24,3 @@ "main": "lib/index.js",

"dependencies": {
"null-logger": "^1.0.0"
},

@@ -26,0 +27,0 @@ "devDependencies": {

@@ -12,4 +12,28 @@ # Retry Machine

const runner = retry({ max: 5, delay: 1000, factor: 2 });
async function failure(e, attempt) {
console.error(e);
}
const runner = retry({ max: 5, delay: 1000, factor: 2 }, failure);
await runner(run, 1);
```
```
---
Optionally pass in a logger:
```javascript
const { retry } = require('retry-machine');
const logger = require('./logger');
async function run(count) {
console.log(count);
}
async function failure(e, attempt) {
console.error(e);
}
const runner = retry({ max: 5, delay: 1000, factor: 2, logger }, failure);
await runner(run, 1);
```
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