UNPKG

@jonaskello-forks/amqp-client

Version:

AMQP 0-9-1 client, both for browsers (WebSocket) and node (TCP Socket)

46 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AMQPConsumer = void 0; const amqp_error_js_1 = require("./amqp-error.js"); class AMQPConsumer { constructor(channel, tag, onMessage) { this.closed = false; this.channel = channel; this.tag = tag; this.onMessage = onMessage; } wait(timeout) { if (this.closedError) return Promise.reject(this.closedError); if (this.closed) return Promise.resolve(); return new Promise((resolve, reject) => { this.resolveWait = resolve; this.rejectWait = reject; if (timeout) { const onTimeout = () => reject(new amqp_error_js_1.AMQPError("Timeout", this.channel.connection)); this.timeoutId = setTimeout(onTimeout, timeout); } }); } cancel() { return this.channel.basicCancel(this.tag); } setClosed(err) { this.closed = true; if (err) this.closedError = err; if (this.timeoutId) clearTimeout(this.timeoutId); if (err) { if (this.rejectWait) this.rejectWait(err); } else { if (this.resolveWait) this.resolveWait(); } } } exports.AMQPConsumer = AMQPConsumer; //# sourceMappingURL=amqp-consumer.js.map