forked from sashin/sashinexists
run npm install to generate a package lock
This commit is contained in:
46
node_modules/stubborn-fs/dist/retryify.js
generated
vendored
Normal file
46
node_modules/stubborn-fs/dist/retryify.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/* IMPORT */
|
||||
import RetryfyQueue from './retryify_queue.js';
|
||||
/* MAIN */
|
||||
//FIXME: There are a boatload of anys here, but apparently generics cannot be extended properly, so...
|
||||
const retryifyAsync = (fn, isRetriableError) => {
|
||||
return function retrified(timestamp) {
|
||||
return function attempt(...args) {
|
||||
return RetryfyQueue.schedule().then(cleanup => {
|
||||
const onResolve = (result) => {
|
||||
cleanup();
|
||||
return result;
|
||||
};
|
||||
const onReject = (error) => {
|
||||
cleanup();
|
||||
if (Date.now() >= timestamp)
|
||||
throw error;
|
||||
if (isRetriableError(error)) {
|
||||
const delay = Math.round(100 * Math.random());
|
||||
const delayPromise = new Promise(resolve => setTimeout(resolve, delay));
|
||||
return delayPromise.then(() => attempt.apply(undefined, args));
|
||||
}
|
||||
throw error;
|
||||
};
|
||||
return fn.apply(undefined, args).then(onResolve, onReject);
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
const retryifySync = (fn, isRetriableError) => {
|
||||
return function retrified(timestamp) {
|
||||
return function attempt(...args) {
|
||||
try {
|
||||
return fn.apply(undefined, args);
|
||||
}
|
||||
catch (error) {
|
||||
if (Date.now() > timestamp)
|
||||
throw error;
|
||||
if (isRetriableError(error))
|
||||
return attempt.apply(undefined, args);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
/* EXPORT */
|
||||
export { retryifyAsync, retryifySync };
|
||||
Reference in New Issue
Block a user