<commit_before>'use strict'

const amqplib = require('amqplib');
const util = require('util');

class ErrorHelper {
    static defaultError(ex) {
        console.log('ERROR in rabbit-listener: ' + util.inspect(ex, { depth: null }));
    }
}

class RabbitListener {
    constructor(options) {

        if (!options)
            options = {};

        this.handleError = options.handleError || ErrorHelper.defaultError;
        this.silent = options.silent || false;

        const protocol = options.protocol || 'amqp';
        const username = options.username || 'guest';
        const password = options.password || '<PASSWORD>';
        const host = options.host || 'localhost';
        const virtualHost = options.virtualHost ? '/%2F' + options.virtualHost : '';
        const port = options.port || 5672;

        this.amqp = {};
        this.amqp.host = `${protocol}://${username}:${password}@${host}${virtualHost}:${port}`;

        this.amqp.exchangeType = options.exchangeType || 'topic';
        this.amqp.exchangeName = options.exchangeName || 'rabbit-chat';
        this.amqp.durable = options.durable || false;

        this._connection = null;
        this._connectionTimer = null;
    }

    static rabbit(options) {
        return new RabbitListener(options);
    }

    listen(callback, properties, callbackOnClose) {
        let t = this;
        let connectionCloseTimerId;

        properties = properties || {};
        
        callback = callback || () => {};
        callbackOnClose = callbackOnClose || () => {};

        return t.getConnection()
            .then((channel) => {
                return channel.assertExchange(t.amqp.exchangeName, t.amqp.exchangeType, { durable: t.amqp.durable })
                    .then((ok) => {
                        return channel.assertQueue('', { exclusive: true })
                            .then((q) => {
                            	
                                channel.bindQueue(q.queue, t.amqp.exchangeName, '');

                                return channel.consume(q.queue, (msg) => {

                                	callback(msg);
                                    clearTimeout(connectionCloseTimerId);

                                    connectionCloseTimerId = setTimeout(() => {
                                        t._connection.close();
                                        t._connection = null;
                                        callbackOnClose();
                                    }, 500);<commit_msg>Removed an unused parameter<commit_after>'use strict'

const amqplib = require('amqplib');
const util = require('util');

class ErrorHelper {
    static defaultError(ex) {
        console.log('ERROR in rabbit-listener: ' + util.inspect(ex, { depth: null }));
    }
}

class RabbitListener {
    constructor(options) {

        if (!options)
            options = {};

        this.handleError = options.handleError || ErrorHelper.defaultError;
        this.silent = options.silent || false;

        const protocol = options.protocol || 'amqp';
        const username = options.username || 'guest';
        const password = options.password || '<PASSWORD>';
        const host = options.host || 'localhost';
        const virtualHost = options.virtualHost ? '/%2F' + options.virtualHost : '';
        const port = options.port || 5672;

        this.amqp = {};
        this.amqp.host = `${protocol}://${username}:${password}@${host}${virtualHost}:${port}`;

        this.amqp.exchangeType = options.exchangeType || 'topic';
        this.amqp.exchangeName = options.exchangeName || 'rabbit-chat';
        this.amqp.durable = options.durable || false;

        this._connection = null;
        this._connectionTimer = null;
    }

    static rabbit(options) {
        return new RabbitListener(options);
    }

    listen(callback, callbackOnClose) {
        let t = this;
        let connectionCloseTimerId;

        callback = callback || () => {};
        callbackOnClose = callbackOnClose || () => {};

        return t.getConnection()
            .then((channel) => {
                return channel.assertExchange(t.amqp.exchangeName, t.amqp.exchangeType, { durable: t.amqp.durable })
                    .then((ok) => {
                        return channel.assertQueue('', { exclusive: true })
                            .then((q) => {

                                channel.bindQueue(q.queue, t.amqp.exchangeName, '');

                                return channel.consume(q.queue, (msg) => {

                                	callback(msg);
                                    clearTimeout(connectionCloseTimerId);

                                    connectionCloseTimerId = setTimeout(() => {
                                        t._connection.close();
                                        t._connection = null;
                                        callbackOnClose();
                                    }, 500);
{'fraction_non_alphanumeric': 0.12588401697312587, 'fraction_numerical': 0.0032329763588603757, 'mean_word_length': 1.6357827476038338, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2812249', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1195, 'n_words': 235}