1const promiseWithTimeout = promise => {
2 let timeoutId;
3 const timeoutPromise = new Promise((_, reject) => {
4 timeoutId = setTimeout(() => {
5 reject(new Error('Request timed out'));
6 }, 4000); })
7 return {
8 promiseOrTimeout: Promise.race([promise, timeoutPromise]),
9 timeoutId, };
10};