@chriscdn/promise-retry 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ env: {
3
+ commonjs: true,
4
+ es2021: true,
5
+ node: true,
6
+ },
7
+ extends: 'eslint:recommended',
8
+ parserOptions: {
9
+ ecmaVersion: 'latest',
10
+ },
11
+ rules: {
12
+ 'no-unused-vars': [
13
+ 'error',
14
+ {
15
+ argsIgnorePattern: '^_',
16
+ varsIgnorePattern: '^_',
17
+ },
18
+ ],
19
+ },
20
+ }
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true
4
+ }
package/lib/index.cjs.js CHANGED
@@ -1,25 +1,25 @@
1
1
  'use strict';
2
2
 
3
3
  const defaultOptions = {
4
- maxAttempts: 10,
5
- milliseconds: 0
4
+ maxAttempts: 10,
5
+ milliseconds: 0,
6
6
  };
7
7
 
8
8
  function promiseRetry(func, options = defaultOptions, attempt = 1) {
9
+ const config = { ...defaultOptions, ...options };
9
10
 
10
- const config = { ...defaultOptions, ...options };
11
-
12
- return func(attempt)
13
- .catch(err => {
14
- if (attempt < config.maxAttempts) {
15
- // return promiseRetry(func, options, attempt + 1)
16
- return new Promise(resolve => {
17
- setTimeout(() => resolve(promiseRetry(func, options, attempt + 1)), config.milliseconds);
18
- })
19
- } else {
20
- throw err
21
- }
22
- })
11
+ return func(attempt).catch((err) => {
12
+ if (attempt < config.maxAttempts) {
13
+ return new Promise((resolve) => {
14
+ setTimeout(
15
+ () => resolve(promiseRetry(func, options, attempt + 1)),
16
+ config.milliseconds
17
+ );
18
+ })
19
+ } else {
20
+ throw err
21
+ }
22
+ })
23
23
  }
24
24
 
25
25
  module.exports = promiseRetry;
package/lib/index.es.js CHANGED
@@ -1,23 +1,23 @@
1
1
  const defaultOptions = {
2
- maxAttempts: 10,
3
- milliseconds: 0
2
+ maxAttempts: 10,
3
+ milliseconds: 0,
4
4
  };
5
5
 
6
6
  function promiseRetry(func, options = defaultOptions, attempt = 1) {
7
+ const config = { ...defaultOptions, ...options };
7
8
 
8
- const config = { ...defaultOptions, ...options };
9
-
10
- return func(attempt)
11
- .catch(err => {
12
- if (attempt < config.maxAttempts) {
13
- // return promiseRetry(func, options, attempt + 1)
14
- return new Promise(resolve => {
15
- setTimeout(() => resolve(promiseRetry(func, options, attempt + 1)), config.milliseconds);
16
- })
17
- } else {
18
- throw err
19
- }
20
- })
9
+ return func(attempt).catch((err) => {
10
+ if (attempt < config.maxAttempts) {
11
+ return new Promise((resolve) => {
12
+ setTimeout(
13
+ () => resolve(promiseRetry(func, options, attempt + 1)),
14
+ config.milliseconds
15
+ );
16
+ })
17
+ } else {
18
+ throw err
19
+ }
20
+ })
21
21
  }
22
22
 
23
23
  var src = promiseRetry;
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
- "name": "@chriscdn/promise-retry",
3
- "version": "1.0.2",
4
- "description": "Retry a function returning a rejected promise until it resolves.",
5
- "main": "lib/index.cjs.js",
6
- "module": "lib/index.es.js",
7
- "repository": "https://github.com/chriscdn/promise-retry",
8
- "author": "Christopher Meyer <chris@schwiiz.org>",
9
- "license": "MIT",
10
- "scripts": {
11
- "build": "rollup -c",
12
- "watch": "rollup -c --watch"
13
- },
14
- "devDependencies": {
15
- "@rollup/plugin-commonjs": "^21.0.2"
16
- },
17
- "keywords": [
18
- "promise",
19
- "retry"
20
- ]
2
+ "name": "@chriscdn/promise-retry",
3
+ "version": "1.0.3",
4
+ "description": "Retry a function returning a rejected promise until it resolves.",
5
+ "main": "lib/index.cjs.js",
6
+ "module": "lib/index.es.js",
7
+ "repository": "https://github.com/chriscdn/promise-retry",
8
+ "author": "Christopher Meyer <chris@schwiiz.org>",
9
+ "license": "MIT",
10
+ "scripts": {
11
+ "build": "rollup -c",
12
+ "watch": "rollup -c --watch"
13
+ },
14
+ "devDependencies": {
15
+ "@rollup/plugin-commonjs": "^21.0.2"
16
+ },
17
+ "keywords": [
18
+ "promise",
19
+ "retry"
20
+ ]
21
21
  }
package/rollup.config.js CHANGED
@@ -1,19 +1,24 @@
1
1
  import pkg from './package.json'
2
2
  import commonjs from '@rollup/plugin-commonjs'
3
3
 
4
- export default [{
5
- input: 'src/index.js',
6
- output: [{
7
- file: pkg.main,
8
- format: 'cjs'
9
- }]
10
- }, {
11
- input: 'src/index.js',
12
- output: [{
13
- file: pkg.module,
14
- format: 'es'
15
- }],
16
- plugins: [
17
- commonjs()
18
- ]
19
- }]
4
+ export default [
5
+ {
6
+ input: 'src/index.js',
7
+ output: [
8
+ {
9
+ file: pkg.main,
10
+ format: 'cjs',
11
+ },
12
+ ],
13
+ },
14
+ {
15
+ input: 'src/index.js',
16
+ output: [
17
+ {
18
+ file: pkg.module,
19
+ format: 'es',
20
+ },
21
+ ],
22
+ plugins: [commonjs()],
23
+ },
24
+ ]
package/src/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  const defaultOptions = {
2
- maxAttempts: 10,
3
- milliseconds: 0
2
+ maxAttempts: 10,
3
+ milliseconds: 0,
4
4
  }
5
5
 
6
6
  function promiseRetry(func, options = defaultOptions, attempt = 1) {
7
+ const config = { ...defaultOptions, ...options }
7
8
 
8
- const config = { ...defaultOptions, ...options }
9
-
10
- return func(attempt)
11
- .catch(err => {
12
- if (attempt < config.maxAttempts) {
13
- // return promiseRetry(func, options, attempt + 1)
14
- return new Promise(resolve => {
15
- setTimeout(() => resolve(promiseRetry(func, options, attempt + 1)), config.milliseconds)
16
- })
17
- } else {
18
- throw err
19
- }
20
- })
9
+ return func(attempt).catch((err) => {
10
+ if (attempt < config.maxAttempts) {
11
+ return new Promise((resolve) => {
12
+ setTimeout(
13
+ () => resolve(promiseRetry(func, options, attempt + 1)),
14
+ config.milliseconds
15
+ )
16
+ })
17
+ } else {
18
+ throw err
19
+ }
20
+ })
21
21
  }
22
22
 
23
- module.exports = promiseRetry
23
+ module.exports = promiseRetry