11 lines
295 B
TypeScript
11 lines
295 B
TypeScript
export function isPromise<T>(value: T | Promise<T>): value is Promise<T> {
|
|
return typeof (value as Promise<T>)?.then === 'function';
|
|
}
|
|
|
|
export async function awaitMaybePromise<T>(value: T | Promise<T>) {
|
|
if (isPromise(value)) {
|
|
return await value;
|
|
}
|
|
return Promise.resolve(value);
|
|
}
|