Spaces:
Paused
Paused
Download node_modules/async-retry/lib/index.js from Huzaifa1313/Prof_app: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/Huzaifa1313/Prof_app/resolve/main/node_modules/async-retry/lib/index.js
- Command line
-
hf download hf://spaces/Huzaifa1313/Prof_app/node_modules/async-retry/lib/index.js
-
curl -L -o index.js https://huggingface.co/spaces/Huzaifa1313/Prof_app/resolve/main/node_modules/async-retry/lib/index.js
1.18 kB
| // Packages | |
| var retrier = require('retry'); | |
| function retry(fn, opts) { | |
| function run(resolve, reject) { | |
| var options = opts || {}; | |
| var op; | |
| // Default `randomize` to true | |
| if (!('randomize' in options)) { | |
| options.randomize = true; | |
| } | |
| op = retrier.operation(options); | |
| // We allow the user to abort retrying | |
| // this makes sense in the cases where | |
| // knowledge is obtained that retrying | |
| // would be futile (e.g.: auth errors) | |
| function bail(err) { | |
| reject(err || new Error('Aborted')); | |
| } | |
| function onError(err, num) { | |
| if (err.bail) { | |
| bail(err); | |
| return; | |
| } | |
| if (!op.retry(err)) { | |
| reject(op.mainError()); | |
| } else if (options.onRetry) { | |
| options.onRetry(err, num); | |
| } | |
| } | |
| function runAttempt(num) { | |
| var val; | |
| try { | |
| val = fn(bail, num); | |
| } catch (err) { | |
| onError(err, num); | |
| return; | |
| } | |
| Promise.resolve(val) | |
| .then(resolve) | |
| .catch(function catchIt(err) { | |
| onError(err, num); | |
| }); | |
| } | |
| op.attempt(runAttempt); | |
| } | |
| return new Promise(run); | |
| } | |
| module.exports = retry; | |