Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"curly": false,
"eqeqeq": true,
"eqnull": true,
"es5": false,
"esnext": true,
"esversion": 6,
"immed": true,
"jquery": true,
"latedef": true,
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ 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;
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 '';
}
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,
Expand All @@ -37,10 +37,10 @@ module.exports = function delayer(channel, opts) {
'x-expires': ttl + opts.threshold
}
});
}).then(function () {
}).then(() => {
return channel.bindQueue(name, name, '#');
}).then(function () {
return channel.publish(name, routingKey, content, options);
}).then(() => {
return channel.publish(name, routingKey, content, options, cb);
});
}
};
Expand Down