UNPKG

@backstage/backend-test-utils

Version:

Test helpers library for Backstage backends

29 lines (25 loc) 747 B
'use strict'; var errors = require('@backstage/errors'); async function waitForReady(probe, label, timeoutMs = 3e4) { const startTime = Date.now(); let lastError; let attempts = 0; for (; ; ) { attempts += 1; try { if (await probe()) { return; } } catch (e) { lastError = e; } if (Date.now() - startTime > timeoutMs) { throw new Error( `Timed out waiting for ${label} to be ready for connections, ${attempts} attempts, ${lastError ? `last error was ${errors.stringifyError(lastError)}` : "(no errors thrown)"}` ); } await new Promise((resolve) => setTimeout(resolve, 100)); } } exports.waitForReady = waitForReady; //# sourceMappingURL=waitForReady.cjs.js.map