Socket
Socket
Sign inDemoInstall

retry-promise-func

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retry-promise-func - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/index.d.ts

60

lib/index.amd.js
define(['exports'], (function (exports) { 'use strict';
/**
* 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数
*
* @param fn 需要调用的函数,它应该返回一个Promise
* @param params 调用函数时使用的参数
* @param times 最大重试次数,默认为40次
* @param delay 每次重试之间的延迟时间(毫秒),默认为1600ms
*
* @returns 当函数调用成功时解决Promise,否则拒绝Promise
*/
const retry = async (fn, params = {}, times = 40, delay = 1600) => {
return new Promise((resolve, reject) => {
const tFn = function () {
fn(params)
.then(resolve)
.catch((e) => {
if (times-- > 0) {
console.log(`还有${times}次机会`);
setTimeout(tFn, delay);
}
else {
reject(e);
}
});
};
return tFn();
});
};
/**
* 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数
*
* @param fn 需要调用的函数,它应该返回一个Promise
* @param params 调用函数时使用的参数
* @param times 最大重试次数,默认为40次
* @param delay 每次重试之间的延迟时间(毫秒),默认为1600ms
*
* @returns 当函数调用成功时解决Promise,否则拒绝Promise
*/
const retry = async (fn, params = {}, times = 40, delay = 1600) => {
return new Promise((resolve, reject) => {
const tFn = function () {
fn(params)
.then(resolve)
.catch((e) => {
if (times-- > 0) {
console.log(`还有${times}次机会`);
setTimeout(tFn, delay);
}
else {
reject(e);
}
});
};
return tFn();
});
};
exports.retry = retry;
exports.retry = retry;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.amd.js.map
var RetryPromiseFunc = (function (exports) {
'use strict';
'use strict';
/**
* 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数
*
* @param fn 需要调用的函数,它应该返回一个Promise
* @param params 调用函数时使用的参数
* @param times 最大重试次数,默认为40次
* @param delay 每次重试之间的延迟时间(毫秒),默认为1600ms
*
* @returns 当函数调用成功时解决Promise,否则拒绝Promise
*/
const retry = async (fn, params = {}, times = 40, delay = 1600) => {
return new Promise((resolve, reject) => {
const tFn = function () {
fn(params)
.then(resolve)
.catch((e) => {
if (times-- > 0) {
console.log(`还有${times}次机会`);
setTimeout(tFn, delay);
}
else {
reject(e);
}
});
};
return tFn();
});
};
/**
* 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数
*
* @param fn 需要调用的函数,它应该返回一个Promise
* @param params 调用函数时使用的参数
* @param times 最大重试次数,默认为40次
* @param delay 每次重试之间的延迟时间(毫秒),默认为1600ms
*
* @returns 当函数调用成功时解决Promise,否则拒绝Promise
*/
const retry = async (fn, params = {}, times = 40, delay = 1600) => {
return new Promise((resolve, reject) => {
const tFn = function () {
fn(params)
.then(resolve)
.catch((e) => {
if (times-- > 0) {
console.log(`还有${times}次机会`);
setTimeout(tFn, delay);
}
else {
reject(e);
}
});
};
return tFn();
});
};
exports.retry = retry;
exports.retry = retry;
return exports;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
})({});
//# sourceMappingURL=index.iife.js.map
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**

@@ -4,0 +6,0 @@ * 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.RetryPromiseFunc = {}));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.RetryPromiseFunc = {}));
})(this, (function (exports) { 'use strict';
/**
* 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数
*
* @param fn 需要调用的函数,它应该返回一个Promise
* @param params 调用函数时使用的参数
* @param times 最大重试次数,默认为40次
* @param delay 每次重试之间的延迟时间(毫秒),默认为1600ms
*
* @returns 当函数调用成功时解决Promise,否则拒绝Promise
*/
const retry = async (fn, params = {}, times = 40, delay = 1600) => {
return new Promise((resolve, reject) => {
const tFn = function () {
fn(params)
.then(resolve)
.catch((e) => {
if (times-- > 0) {
console.log(`还有${times}次机会`);
setTimeout(tFn, delay);
}
else {
reject(e);
}
});
};
return tFn();
});
};
/**
* 尝试多次调用一个函数,如果失败则重试,直到成功或超过重试次数
*
* @param fn 需要调用的函数,它应该返回一个Promise
* @param params 调用函数时使用的参数
* @param times 最大重试次数,默认为40次
* @param delay 每次重试之间的延迟时间(毫秒),默认为1600ms
*
* @returns 当函数调用成功时解决Promise,否则拒绝Promise
*/
const retry = async (fn, params = {}, times = 40, delay = 1600) => {
return new Promise((resolve, reject) => {
const tFn = function () {
fn(params)
.then(resolve)
.catch((e) => {
if (times-- > 0) {
console.log(`还有${times}次机会`);
setTimeout(tFn, delay);
}
else {
reject(e);
}
});
};
return tFn();
});
};
exports.retry = retry;
exports.retry = retry;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.umd.js.map
{
"name": "retry-promise-func",
"version": "1.0.0",
"version": "1.0.1",
"description": "retry-promise-func是一个用于在失败时重试Promise调用的工具。",
"main": "./lib",
"main": "lib/index.js",
"module": "lib/index.esm.js",
"jsnext:main": "lib/index.esm.js",
"browser": "lib/index.umd.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"scripts": {
"build": "rollup -c",
"clean": "rimraf ./lib",
"clean": "rimraf lib",
"prepare": "npm run clean && npm run build"
},
"type": "module",
"author": "Chain <caohuiboss@qq.com>",
"author": "China <caohuiboss@qq.com>",
"license": "ISC",

@@ -28,14 +35,16 @@ "keywords": [

"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"rimraf": "^4.1.2",
"rollup": "^3.15.0",
"rollup": "^2.62.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.9.5"
"rollup-plugin-typescript2": "^0.34.1",
"typescript": "^4.5.5"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"tslib": "^2.5.0"
}
}

@@ -7,5 +7,5 @@ # retry-promise-func

使用 npm 安装: npm install retry-promise-func
> 使用 npm 安装: npm install retry-promise-func
使用 yarn 安装: yarn add retry-promise-func
> 使用 yarn 安装: yarn add retry-promise-func

@@ -17,7 +17,27 @@ ## 使用

```typescript
import { retry } from "retry-promise";
import { retry } from "retry-promise-func";
retry(someFunction, someParams, 10, 2000)
.then((result) => console.log(result))
.catch((error) => console.error(error));
const someFunction = async (someParams) => {
return new Promise((resolve, reject) => {
console.log(someParams);
setTimeout(() => {
if (Math.random() > 0.5) {
resolve("Success");
} else {
reject("Failure");
}
}, 1000);
});
};
const main = async () => {
try {
const result = await retry(someFunction, { a: 1 }, 10, 2000);
console.log(result);
} catch (error) {
console.log(error);
}
};
main();
```

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

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