Files
SupportBot/Structures/asyncTimeout.js
T
2026-05-16 15:10:27 +01:00

15 lines
344 B
JavaScript

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 };