MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / retry

Function retry

javascriptv3/example_code/libs/utils/util-timers.js:17–46  ·  view source on GitHub ↗
(config, fn)

Source from the content-addressed store, hash-verified

15 * @returns {Promise<T>}
16 */
17const retry = (config, fn) =>
18 new Promise((resolve, reject) => {
19 const { intervalInMs = 500, maxRetries = 10, backoff = 0 } = config;
20 fn()
21 .then(resolve)
22 .catch((err) => {
23 if (!config.quiet) {
24 console.warn(
25 `Retrying after ${
26 intervalInMs / 1000
27 } seconds. ${maxRetries} retries left.`,
28 );
29 console.warn(err instanceof Error ? err.message : err);
30 }
31 if (maxRetries === 0) {
32 config.swallowError ? resolve() : reject(err);
33 } else {
34 setTimeout(() => {
35 retry(
36 {
37 ...config,
38 intervalInMs: intervalInMs + backoff,
39 maxRetries: maxRetries - 1,
40 },
41 fn,
42 ).then(resolve, reject);
43 }, intervalInMs);
44 }
45 });
46 });
47
48export { retry, wait };

Callers 15

import-steps.jsFile · 0.90
deploy-steps.jsFile · 0.90
steps-deploy.jsFile · 0.90
steps-destroy.jsFile · 0.90
terminateGroupInstancesFunction · 0.90
steps-demo.jsFile · 0.90
_waitUntilQueryDoneMethod · 0.90
initializeLambdaFunctionFunction · 0.90
testDeleteFilterFunction · 0.90
testCreateFunctionFunction · 0.90

Calls

no outgoing calls

Tested by 4

initializeLambdaFunctionFunction · 0.72
testDeleteFilterFunction · 0.72
testCreateFunctionFunction · 0.72
getMessagesFromQueueFunction · 0.72