/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ /** * @internal */ export interface TimeoutDurationOption { /** * Timeout duration in milliseconds, if it is great than 0 and not Infinity * If it is undefined, then it will use test timeout if we are in side the test function * Otherwise, there is no timeout */ durationMs?: number; } /** * @internal */ export interface TimeoutWithError extends TimeoutDurationOption { reject?: true; errorMsg?: string; value?: never; } /** * @internal */ export interface TimeoutWithValue extends TimeoutDurationOption { reject: false; value: T; } export type PromiseExecutor = (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void; /** * Wraps the given promise with another one that will complete after a specific timeout if the original promise does * not resolve by then. * * @remarks * If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before * the test timeout hits, so that tests don't time out because of unpredictable awaits. * In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value. * * @param promise - The promise to be wrapped. * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when * the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value. * @returns A new promise that will complete when the given promise resolves or the timeout expires. * @internal */ export declare function timeoutAwait(promise: PromiseLike, timeoutOptions?: TimeoutWithError | TimeoutWithValue): Promise; /** * Creates a promise from the given executor that will complete after a specific timeout. * * @remarks * If used inside a mocha test, it uses the test timeout by default and completes the returned promise just before * the test timeout hits, so that tests don't time out because of unpredictable awaits. * In that scenario the timeout can still be overridden via `timeoutOptions` but it's recommended to use the default value. * * @param executor - The executor for the promise. * @param timeoutOptions - Options that can be used to override the timeout and / or define the behavior when * the promise is not fulfilled. For example, instead of rejecting the promise, resolve with a specific value. * @returns A new promise that will complete when the given executor resolves or the timeout expires. * @internal */ export declare function timeoutPromise(executor: (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void, timeoutOptions?: TimeoutWithError | TimeoutWithValue): Promise; //# sourceMappingURL=timeoutUtils.d.ts.map