@songkeys/nestjs-redis-health
Version:
Redis(ioredis) health checks module for Nest framework (node.js).
23 lines (22 loc) • 739 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.promiseTimeout = void 0;
const messages_1 = require("../messages");
/**
* Executes a promise in the given timeout. If the promise does not finish in the given timeout, it will throw an Error.
*
* @param ms - The timeout in milliseconds
* @param promise - The promise which should get executed
*/
const promiseTimeout = (ms, promise) => {
let timer;
return Promise.race([
promise,
new Promise((_, reject) => {
timer = setTimeout(() => reject(new Error((0, messages_1.OPERATIONS_TIMEOUT)(ms))), ms);
})
]).finally(() => {
clearTimeout(timer);
});
};
exports.promiseTimeout = promiseTimeout;