@player-ui/player
Version:
31 lines • 1.72 kB
TypeScript
/**
* Promise detection that handles various Promise implementations
* and reduces false positives from objects with coincidental 'then' methods
*/
export declare function isPromiseLike(value: any): value is Promise<any>;
/** Unique private symbol to indicate async functions wrapped in Player's await function */
export declare const AwaitableSymbol: unique symbol;
/**
* Wrapper for Promises that are generated from the `await` function with a unique symbol so we can
* determine when a promise should be awaited by us (as its returned by await) or a promise thats
* generated from any async function
*/
export interface Awaitable<T> extends Promise<T> {
/** Prevent unwrapped then from being exposed from underlying promise */
then: never;
/** Internalally awaitable wrapper around underlying then function */
awaitableThen<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
/** Symbol to identify this as something returned by await */
[AwaitableSymbol]: symbol;
}
/** Typeguard for AwaitableResult */
export declare function isAwaitable(val: unknown): val is Awaitable<any>;
/**
* Wraps Promise.all in AwaitableResult wrapper to allow internal functions to await internally produced promises
*/
export declare function collateAwaitable<T extends readonly unknown[] | []>(promises: T): Awaitable<any>;
/**
* Add AwaitableSymbol to base promise and promise returned by then() function
*/
export declare function makeAwaitable(promise: Promise<any>): Awaitable<any>;
//# sourceMappingURL=async.d.ts.map