-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 854 Bytes
/
index.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
'use strict';
var Q = require('q');
function addEvent(eventObject, event, func) {
this.promiseDb = [];
this.match = function () {
return true;
}
var that = this;
eventObject.on(event, function(data) {
that.promiseDb.forEach(function(p) {
if (that.match(data, p.input)) {
p.promise.resolve(data);
}
});
});
var promiseFunction = function(input) {
var deferred = Q.defer();
var e2pItem = {
promise: deferred,
input: input
};
that.promiseDb.push(e2pItem);
func(input);
return deferred.promise;
};
promiseFunction.match = function(func) {
that.match = func;
return promiseFunction;
};
return promiseFunction;
}
module.exports = {
wrapFunction: addEvent
};