UNPKG

nestjs-resilience

Version:

A module for improving the reliability and fault-tolerance of your NestJS applications

23 lines (22 loc) 840 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeoutStrategy = void 0; const base_strategy_1 = require("./base.strategy"); const rxjs_1 = require("rxjs"); const exceptions_1 = require("../exceptions"); class TimeoutStrategy extends base_strategy_1.Strategy { constructor(options = TimeoutStrategy.DEFAULT_OPTIONS) { super(options); if (this.options <= 0) { throw new RangeError('Timeout must be greater than 0, got: ' + this.options); } } process(observable) { return observable.pipe((0, rxjs_1.timeout)({ each: this.options, with: () => (0, rxjs_1.throwError)(() => new exceptions_1.TimeoutException(this.options)) })); } } exports.TimeoutStrategy = TimeoutStrategy; TimeoutStrategy.DEFAULT_OPTIONS = 1000;