Files
memecoin-botV2/.pnpm-store/v10/files/70/17d66acc3eaeac190c2765555c60847de69d4c5e149ad2250a72aebc8d90b361ad6bed46d3f22f6a77cc6aa7d41984ab8808743be02eed484c05d0ad96e1aa

15 lines
416 B
Plaintext

export function promiseTimeout<T>(
promise: Promise<T>,
timeoutMs: number,
): Promise<T | null> {
let timeoutId: ReturnType<typeof setTimeout>;
const timeoutPromise: Promise<null> = new Promise(resolve => {
timeoutId = setTimeout(() => resolve(null), timeoutMs);
});
return Promise.race([promise, timeoutPromise]).then((result: T | null) => {
clearTimeout(timeoutId);
return result;
});
}