File size: 239 Bytes
992a8de
 
 
 
 
 
1
2
3
4
5
6
7
export const timeout = <T>(prom: Promise<T>, time: number): Promise<T> => {
	let timer: NodeJS.Timeout;
	return Promise.race([prom, new Promise<T>((_r, rej) => (timer = setTimeout(rej, time)))]).finally(
		() => clearTimeout(timer)
	);
};