UNPKG

matterbridge

Version:
52 lines 3.09 kB
/** * This file contains the wait, waiter and withTimeout functions. * * @file wait.ts * @author Luca Liguori * @date 2025-02-16 * @version 1.0.1 * * Copyright 2025, 2026, 2027 Luca Liguori. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import { AnsiLogger } from '../logger/export.js'; export declare const log: AnsiLogger; /** * Asynchronous waiter function that resolves when the provided condition is met or rejects on timeout. * @param {string} name - The name of the waiter. * @param {() => boolean} check - A function that checks the condition. Should return a boolean. * @param {boolean} [exitWithReject=false] - Optional. If true, the promise will be rejected on timeout. Default is false. * @param {number} [resolveTimeout=5000] - Optional. The timeout duration in milliseconds. Default is 5000ms. * @param {number} [resolveInterval=500] - Optional. The interval duration in milliseconds between condition checks. Default is 500ms. * @param {boolean} [debug=false] - Optional. If true, debug messages will be logged to the console. Default is false. * @returns {Promise<boolean>} A promise that resolves to true when the condition is met, or false if the timeout occurs. */ export declare function waiter(name: string, check: () => boolean, exitWithReject?: boolean, resolveTimeout?: number, resolveInterval?: number, debug?: boolean): Promise<boolean>; /** * Asynchronously waits for a specified amount of time. * @param {number} timeout - The duration to wait in milliseconds. Default is 1000ms. * @param {string} name - The name of the wait operation. Default is undefined. * @param {boolean} debug - Whether to enable debug logging. Default is false. * @returns {Promise<void>} A Promise that resolves after the specified timeout. */ export declare function wait(timeout?: number, name?: string, debug?: boolean): Promise<void>; /** * Wraps a promise with a timeout. If the promise does not resolve or reject within the specified time, it will be rejected. * @param {Promise<T>} promise - The promise to wrap. * @param {number} [timeoutMillisecs=10000] - The timeout duration in milliseconds. Default is 10000ms. * @param {boolean} [reThrow=true] - Optional. If true, the promise will rethrow the original promise and will reject on timeout. Default is true. * @returns {Promise<T>} A new promise that resolves or rejects based on the original promise and the timeout. */ export declare function withTimeout<T>(promise: Promise<T>, timeoutMillisecs?: number, reThrow?: boolean): Promise<T>; //# sourceMappingURL=wait.d.ts.map