UNPKG

@muirglacier/testcontainers

Version:

A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance for Bitcoin

43 lines 2.09 kB
"use strict"; /* eslint-disable @typescript-eslint/no-non-null-assertion, no-void */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForCondition = void 0; /** * @param {() => Promise<boolean>} condition to wait for true * @param {number} timeout duration when condition is not met * @param {number} [interval=200] duration in ms * @param {string} message for error */ function waitForCondition(condition, timeout, interval = 200, message = 'waitForCondition') { return __awaiter(this, void 0, void 0, function* () { const expiredAt = Date.now() + timeout; return yield new Promise((resolve, reject) => { function checkCondition() { return __awaiter(this, void 0, void 0, function* () { const isReady = yield condition().catch(() => false); if (isReady) { resolve(); } else if (expiredAt < Date.now()) { reject(new Error(`${message} is not ready within given timeout of ${timeout}ms.`)); } else { setTimeout(() => void checkCondition(), interval); } }); } void checkCondition(); }); }); } exports.waitForCondition = waitForCondition; //# sourceMappingURL=utils.js.map