@augment-vir/common
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -17,1 +17,8 @@ export declare function wait(delayMs: number): Promise<void>; | ||
export declare function createDeferredPromiseWrapper<T = void>(): DeferredPromiseWrapper<T>; | ||
export declare type WaitForConditionInputs = { | ||
conditionCallback: () => boolean | Promise<boolean>; | ||
timeoutMs?: number; | ||
intervalMs?: number; | ||
timeoutMessage?: string; | ||
}; | ||
export declare function waitForCondition({ conditionCallback, timeoutMs, intervalMs, timeoutMessage, }: WaitForConditionInputs): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createDeferredPromiseWrapper = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = exports.wait = void 0; | ||
exports.waitForCondition = exports.createDeferredPromiseWrapper = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = exports.wait = void 0; | ||
const error_1 = require("./error"); | ||
const object_1 = require("./object"); | ||
@@ -69,1 +70,25 @@ function wait(delayMs) { | ||
exports.createDeferredPromiseWrapper = createDeferredPromiseWrapper; | ||
async function waitForCondition({ conditionCallback, timeoutMs = 10000, intervalMs = 100, timeoutMessage = '', }) { | ||
let condition = false; | ||
let lastError; | ||
async function checkCondition() { | ||
try { | ||
condition = !!(await conditionCallback()); | ||
} | ||
catch (error) { | ||
condition = false; | ||
lastError = error; | ||
} | ||
} | ||
const startTime = Date.now(); | ||
await checkCondition(); | ||
while (!condition) { | ||
await wait(intervalMs); | ||
if (Date.now() - startTime >= timeoutMs) { | ||
const message = timeoutMessage ? `${timeoutMessage}: ` : ''; | ||
throw new Error(`${message}Timeout of "${timeoutMs}" exceeded waiting for condition to be true${(0, error_1.extractErrorMessage)(lastError)}`); | ||
} | ||
await checkCondition(); | ||
} | ||
} | ||
exports.waitForCondition = waitForCondition; |
{ | ||
"name": "@augment-vir/common", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common", | ||
@@ -5,0 +5,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58255
1213