{"version":3,"file":"retry.mjs","names":[],"sources":["../../src/utils/retry.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport async function retry<T>(\n\tfn: () => Promise<T>,\n\toptions: {\n\t\tcondition?: (error: Error) => boolean;\n\t\tcount?: number;\n\t\tdelay?: number;\n\t\tjitter?: number;\n\t},\n): Promise<T> {\n\tlet remaining = options.count ?? 3;\n\n\twhile (remaining > 0) {\n\t\ttry {\n\t\t\tremaining -= 1;\n\t\t\treturn await fn();\n\t\t} catch (error) {\n\t\t\tif (remaining <= 0 || (options.condition && !options.condition(error as Error))) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tif (options.delay) {\n\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\tsetTimeout(\n\t\t\t\t\t\tresolve,\n\t\t\t\t\t\t(options.delay ?? 1000) + (options.jitter ? Math.random() * options.jitter : 0),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Should never be reached\n\tthrow new Error('Retry count exceeded');\n}\n"],"mappings":";AAGA,eAAsB,MACrB,IACA,SAMa;CACb,IAAI,YAAY,QAAQ,SAAS;AAEjC,QAAO,YAAY,EAClB,KAAI;AACH,eAAa;AACb,SAAO,MAAM,IAAI;UACT,OAAO;AACf,MAAI,aAAa,KAAM,QAAQ,aAAa,CAAC,QAAQ,UAAU,MAAe,CAC7E,OAAM;AAGP,MAAI,QAAQ,MACX,OAAM,IAAI,SAAS,YAClB,WACC,UACC,QAAQ,SAAS,QAAS,QAAQ,SAAS,KAAK,QAAQ,GAAG,QAAQ,SAAS,GAC7E,CACD;;AAMJ,OAAM,IAAI,MAAM,uBAAuB"}