Created
April 30, 2023 23:21
-
-
Save christopherbauer/510b3df74a2b03233b73eb22df2c3a3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Retry = (count: number, waitMS: number) => { | |
return function repeater( | |
originalMethod: Function, | |
_context: ClassMethodDecoratorContext | |
) { | |
function ReplacementMethod(this: any, ...args: any[]) { | |
let tries = 0; | |
const attempt = () => { | |
tries++; | |
try { | |
originalMethod.call(this, ...args); | |
} catch (err) { | |
if (tries < count) { | |
setTimeout(attempt, waitMS); | |
} | |
} | |
}; | |
return attempt(); | |
} | |
return ReplacementMethod; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment