UNPKG

packdir-cli

Version:
26 lines 954 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.retryFetch = exports.uuid = void 0; const tslib_1 = require("tslib"); const fetchable_1 = tslib_1.__importDefault(require("./fetchable")); tslib_1.__exportStar(require("./fetchable"), exports); const uuid = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' .replace(/[xy]/g, c => { const r = Math.random() * 16 | 0; return (c === 'x' ? r : r & 0x3 | 0x8).toString(16); }); exports.uuid = uuid; const retryFetch = async (url, timeout, retry, log) => { for (let i = 0; i < retry - 1; i++) { try { return await (0, fetchable_1.default)(url, timeout); } catch { log(`Failed to fetch \`${url}\` ${i + 1} ${i === 0 ? 'time' : 'times'}. Retrying...`); } } // last try, no catching return (0, fetchable_1.default)(url, timeout); }; exports.retryFetch = retryFetch; //# sourceMappingURL=other.js.map