Files
SupportBot/Structures/asyncTimeout.js
T

14 lines
344 B
JavaScript
Raw Permalink Normal View History

2026-05-16 15:10:27 +01:00
function withTimeout(promise, ms, message) {
let timer;
const timeout = new Promise((_, reject) => {
timer = setTimeout(() => {
reject(new Error(message || `Timed out after ${ms}ms`));
}, ms);
});
return Promise.race([promise, timeout]).finally(() => {
clearTimeout(timer);
});
}
module.exports = { withTimeout };