From 2514f7cbae63cd5c6133c8c01c548fbe4ef839b3 Mon Sep 17 00:00:00 2001 From: lummish Date: Thu, 16 Nov 2017 16:48:39 -0800 Subject: [PATCH 1/2] UPDATE: added support for confirmChannel callbacks --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 70e7fb4..6037666 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ module.exports = function delayer(channel, opts) { channel.delay = function (delayMs) { return { - publish: function (exchange, routingKey, content, options) { + publish: function (exchange, routingKey, content, options, ...[cb]) { delayMs = Math.ceil(delayMs / opts.round) * opts.round; var ttl = delayMs; @@ -40,7 +40,7 @@ module.exports = function delayer(channel, opts) { }).then(function () { return channel.bindQueue(name, name, '#'); }).then(function () { - return channel.publish(name, routingKey, content, options); + return channel.publish(name, routingKey, content, options, cb); }); } }; From e0785d43fee4cfa904a573120d3ed97ddb7b5647 Mon Sep 17 00:00:00 2001 From: lummish Date: Thu, 16 Nov 2017 17:11:03 -0800 Subject: [PATCH 2/2] UPDATE: removed deprecated jshint properties, updated syntax to es6 spec, refactored cb arg --- .jshintrc | 3 +-- index.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.jshintrc b/.jshintrc index c05daca..ec8f6ee 100644 --- a/.jshintrc +++ b/.jshintrc @@ -4,8 +4,7 @@ "curly": false, "eqeqeq": true, "eqnull": true, - "es5": false, - "esnext": true, + "esversion": 6, "immed": true, "jquery": true, "latedef": true, diff --git a/index.js b/index.js index 6037666..f53e6f0 100644 --- a/index.js +++ b/index.js @@ -7,14 +7,14 @@ module.exports = function delayer(channel, opts) { channel.delay = function (delayMs) { return { - publish: function (exchange, routingKey, content, options, ...[cb]) { + publish: function (exchange, routingKey, content, options, cb) { delayMs = Math.ceil(delayMs / opts.round) * opts.round; - var ttl = delayMs; - var time = { ms: 1000, s: 60, m: 60, h: 24, d: 30, mo: 12, y: 999999 }; + let ttl = delayMs; + let time = { ms: 1000, s: 60, m: 60, h: 24, d: 30, mo: 12, y: 999999 }; delayMs = Object.keys(time).map(function(unit) { - var mod = delayMs % time[unit]; + let mod = delayMs % time[unit]; delayMs = Math.floor(delayMs / time[unit]); if (!mod) { return ''; @@ -22,12 +22,12 @@ module.exports = function delayer(channel, opts) { return mod + unit; }).reverse().join(''); - var name = [opts.prefix, exchange, delayMs].join(opts.separator); + let name = [opts.prefix, exchange, delayMs].join(opts.separator); return channel.assertExchange(name, 'fanout', { durable: true, autoDelete: true - }).then(function () { + }).then(() => { return channel.assertQueue(name, { durable: true, autoDelete: true, @@ -37,9 +37,9 @@ module.exports = function delayer(channel, opts) { 'x-expires': ttl + opts.threshold } }); - }).then(function () { + }).then(() => { return channel.bindQueue(name, name, '#'); - }).then(function () { + }).then(() => { return channel.publish(name, routingKey, content, options, cb); }); }