UNPKG

@goparrot/pubsub-event-bus

Version:
45 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AckAndNackStrategy = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const interface_1 = require("../../interface"); const AbstractHandleWrapperStrategy_1 = require("./AbstractHandleWrapperStrategy"); let AckAndNackStrategy = class AckAndNackStrategy extends AbstractHandleWrapperStrategy_1.AbstractHandleWrapperStrategy { constructor() { super(...arguments); this.strategy = interface_1.AutoAckEnum.ACK_AND_NACK; } addAutoAck(handlerWrapper, channelWrapper) { const { handler } = handlerWrapper; const originalMethod = handler.prototype.handle; Reflect.defineProperty(handler.prototype, 'handle', { ...Reflect.getOwnPropertyDescriptor(handler.prototype, 'handle'), async value(event) { try { await originalMethod.apply(this, [event]); const message = event.message(); if (message) { channelWrapper.ack(message); } } catch (e) { const message = event.message(); if (message) { channelWrapper.nack(message); } throw e; } }, }); } process(handlerWrapper, channelWrapper) { this.mockAckAndNack(handlerWrapper); this.addAutoAck(handlerWrapper, channelWrapper); } }; exports.AckAndNackStrategy = AckAndNackStrategy; exports.AckAndNackStrategy = AckAndNackStrategy = tslib_1.__decorate([ (0, common_1.Injectable)() ], AckAndNackStrategy); //# sourceMappingURL=AckAndNackStrategy.js.map