UNPKG

394 BJavaScriptView Raw
1export function requestTimeout(timeoutInMs = 0) {
2 return new Promise((resolve, reject) => {
3 if (timeoutInMs) {
4 setTimeout(() => {
5 const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
6 timeoutError.name = "TimeoutError";
7 reject(timeoutError);
8 }, timeoutInMs);
9 }
10 });
11}