bitcore-wallet-service/lib/utils.js

29 lines
596 B
JavaScript
Raw Normal View History

2015-02-02 10:29:14 -08:00
var $ = require('preconditions').singleton();
var _ = require('lodash');
2015-02-02 11:00:32 -08:00
var Lock = require('./lock');
2015-02-02 10:29:14 -08:00
2015-02-02 11:00:32 -08:00
var Utils = {};
2015-02-02 10:29:14 -08:00
2015-02-02 11:00:32 -08:00
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) {
2015-02-02 10:29:14 -08:00
args = [].concat(args);
if (!_.isObject(obj)) throw 'Required arguments missing';
_.each(args, function (arg) {
if (!obj.hasOwnProperty(arg)) throw "Missing required argument '" + arg + "'";
});
};
2015-02-02 11:00:32 -08:00
module.exports = Utils;