corde
Version:
A simple library for Discord bot tests
28 lines (21 loc) • 566 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.executeWithTimeout = void 0;
const utils_1 = require("./utils");
async function executeWithTimeout(fn, timeout) {
if (!fn) {
throw new Error("can not execute an null function");
}
if (utils_1.utils.isInDebugMode()) {
return await fn();
}
const nodeTimeout = setTimeout(() => {
throw new Error("timeout");
}, timeout);
const response = await fn();
clearTimeout(nodeTimeout);
return response;
}
exports.executeWithTimeout = executeWithTimeout;