Socket
Socket
Sign inDemoInstall

dtimer

Package Overview
Dependencies
6
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.8 to 0.2.0

83

lib/dtimer.js

@@ -107,2 +107,3 @@ 'use strict';

DTimer.prototype._callOnReady = function (cb) {

@@ -339,3 +340,85 @@ var self = this;

DTimer.prototype.upcoming = function(option, cb) {
var self = this;
var defaults = {
offset: -1,
duration: -1, // +inf
limit: -1 // +inf
};
var _option;
if (typeof option !== 'object') {
cb = option;
_option = defaults;
} else {
_option = _und.defaults(option, defaults);
}
this._redisTime(this._pub, function (err, now) {
if (err) { return void(cb(err)); }
var args = [ self._keys.ei ];
var offset = 0;
if (typeof _option.offset !== 'number' || _option.offset < 0) {
args.push(0);
} else {
args.push(now + _option.offset);
offset = _option.offset;
}
if (typeof _option.duration !== 'number' || _option.duration < 0) {
args.push('+inf');
} else {
args.push(now + offset + _option.duration);
}
args.push('WITHSCORES');
if (typeof _option.limit === 'number' && _option.limit > 0) {
args.push('LIMIT');
args.push(0);
args.push(_option.limit);
}
debug('upcoming args: ' + JSON.stringify(args));
self._pub.zrangebyscore(
args,
function(err, results){
if (err) {
return void(cb(err));
}
if (results.length === 0) {
return void(cb(null, {}));
}
var out = [];
args = [ self._keys.ed ];
for (var i = 0; i < results.length; i += 2) {
out.push({ expireAt: parseInt(results[i+1]), id: parseInt(results[i])});
args.push(results[i]);
}
self._pub.hmget(args, function(err, results) {
if (err) {
return void(cb(err));
}
var outObj = {};
results.forEach(function(evStr, index){
/* istanbul ignore if */
if (!evStr) {
return;
}
/* istanbul ignore next */
try {
var event = JSON.parse(evStr);
} catch (e) {
debug(self._id+': fail to parse event. ' + JSON.stringify(e));
return;
}
outObj[out[index].id] = { expireAt : out[index].expireAt, event: event };
});
cb(null, outObj);
});
}
);
});
};
module.exports.DTimer = DTimer;

2

package.json
{
"name": "dtimer",
"version": "0.1.8",
"version": "0.2.0",
"description": "Distributed timer backed by Redis.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -45,3 +45,30 @@ # dtimer

* {number} evId - The event ID obtained via the callback of post() method.
* upcoming([option], cb) - Retrieve upcoming events. This method is provided for diagnostic purpose only and the use of this method in production is hightly discouraged unless the number of events retrieved is reasonably small. Cost of this operation is O(N), where N is the number events that would be retrieved.
* {object} option - Options
* {number} offset Offset expiration time in msec from which events are retrieved . This defaults to the current (redis-server) time (-1).
* {number} duration Time length [msec] from offset time for which events are trieved. This defaults to '+inf' (-1).
* {number} limit Maximum number of events to be retrieved. This defaults to `no limit` (-1)
* {function} cb - Callback made when upcoming operation is complete. The callback function takes following args:
* {Error} err - Error object. Null is set on success.
* {object} events - List of objects that met the given criteria.
Example of retrieved events by upcoming():
```
{
"2": {
"expireAt": 1410502530320,
"event": {
"msg": "hello"
}
},
"3": {
"expireAt": 1410502531321,
"event": {
"msg": "hello"
}
}
}
```
### Instance member (getter/setter)

@@ -48,0 +75,0 @@ * {number} maxEvents (getter&setter) - The max number of events this node can grab at a time. The attempt to set it to 0 or negative value result in setting it to the original value supplied in the option field, or the default (8).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc