forked from Axosoft/node-axosoft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promise.js
37 lines (31 loc) · 848 Bytes
/
promise.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var _ = require('lodash');
var NodeAxosoft = require('./');
function promisify(obj) {
_.forEach(obj, function(fn, key) {
if (_.isFunction(fn)) {
obj[key] = function() {
var args = Array.prototype.slice.call(arguments);
return new Promise(function(resolve, reject) {
args.push(function(error, result) {
if (error) {
reject(error);
} else {
resolve(result);
}
});
fn.apply(null, args);
});
}
}
});
}
module.exports = function NodeAxosoftPromise() {
var nodeAxosoft = NodeAxosoft.apply(null, arguments);
var nodeAxosoftPromise = _.cloneDeep(nodeAxosoft);
_.forEach(nodeAxosoftPromise, function(prop) {
if (_.isObject(prop)) {
promisify(prop);
}
});
return nodeAxosoftPromise;
};