@freemework/common
Version:
Common library of the Freemework Project.
29 lines (28 loc) • 1.58 kB
TypeScript
import { FCancellationToken } from "../cancellation/index.js";
import { FExecutionContext } from "../execution_context/index.js";
/**
* @deprecated Use `fsleep()` instead
*/
export declare function FSleep(cancellationToken: FCancellationToken, ms?: number): Promise<void>;
export declare function FSleep(executionContext: FExecutionContext, ms?: number): Promise<void>;
/**
* Provide a "sleeping" `Promise` that completes via timeout or cancellationToken
* @param cancellationToken The cancellation token to cancel "sleeping"
* @param ms Timeout delay in milliseconds. If omitted, the "sleeping" `Promise` will sleep infinitely and wait for cancellation token activation
* @example
* await fsleep(FCancellationToken.Dummy, 25); // Suspend execution for 25 milliseconds
* @example
* const cancellationTokenSource = new FCancellationTokenSourceManual();
* ...
* await fsleep(cancellationTokenSource.token, 25); // Suspend execution for 25 milliseconds or cancel if cancellationTokenSource activates
* @example
* const cancellationTokenSource = new FCancellationTokenSourceManual();
* ...
* await fsleep(cancellationTokenSource.token); // Suspend infinitely while cancellationTokenSource activates
* @example
* const executionContext: FExecutionContext = ...;
* ...
* await fsleep(executionContext); // Cancellation token will extracted from execution context
*/
export declare function fsleep(cancellationToken: FCancellationToken, ms?: number): Promise<void>;
export declare function fsleep(executionContext: FExecutionContext, ms?: number): Promise<void>;