You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
617 B
28 lines
617 B
var $ = require('preconditions').singleton();
|
|
var _ = require('lodash');
|
|
var Lock = require('./lock');
|
|
|
|
var Utils = {};
|
|
|
|
Utils.runLocked = function (token, cb, task) {
|
|
var self = this;
|
|
|
|
Lock.get(token, function (lock) {
|
|
var _cb = function () {
|
|
cb.apply(null, arguments);
|
|
lock.free();
|
|
};
|
|
task(_cb);
|
|
});
|
|
};
|
|
|
|
|
|
Utils.checkRequired = function (obj, args) {
|
|
args = [].concat(args);
|
|
if (!_.isObject(obj)) throw 'Required arguments missing';
|
|
_.each(args, function (arg) {
|
|
if (!obj.hasOwnProperty(arg)) throw "Missing required argument '" + arg + "'";
|
|
});
|
|
};
|
|
|
|
module.exports = Utils;
|
|
|