@suissa/universal-queues
Version:
Factory universal para mensageria (RabbitMQ, Kafka, SQS) para sistemas distribuĂdos.
18 lines • 658 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeoutError = void 0;
exports.withTimeout = withTimeout;
class TimeoutError extends Error {
constructor(msg = 'Operation timed out') {
super(msg);
this.name = 'TimeoutError';
}
}
exports.TimeoutError = TimeoutError;
function withTimeout(p, ms, label = 'op') {
return new Promise((resolve, reject) => {
const t = setTimeout(() => reject(new TimeoutError(`${label} timeout after ${ms}ms`)), ms);
p.then((v) => { clearTimeout(t); resolve(v); }, (e) => { clearTimeout(t); reject(e); });
});
}
//# sourceMappingURL=timeout.js.map