This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
event_emitter2_ascoltatore.js
84 lines (62 loc) · 1.98 KB
/
event_emitter2_ascoltatore.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
var AbstractAscoltatore = require("./abstract_ascoltatore");
var util = require("./util");
var defer = util.defer;
var debug = require("debug")("ascoltatori:ee2");
var EventEmitter2 = require("eventemitter2").EventEmitter2;
var ascoltatori = require('./ascoltatori');
/**
* A EventEmitter2Ascoltatore is a class that inherits from AbstractAscoltatore.
* It is backed by EventEmitter2.
*
* @api public
*/
function EventEmitter2Ascoltatore(settings) {
AbstractAscoltatore.call(this, settings, {
wildcardOne: '*',
wildcardSome: '**'
});
this._event = new EventEmitter2({
delimiter: this._separator,
wildcard: true
});
this._event.setMaxListeners(0);
this.emit("ready");
}
/**
* See AbstractAscoltatore for the public API definitions.
*
* @api private
*/
EventEmitter2Ascoltatore.prototype = Object.create(AbstractAscoltatore.prototype);
EventEmitter2Ascoltatore.prototype.subscribe = function subscribe(topic, callback, done) {
this._raiseIfClosed();
debug("registered new subscriber for topic " + topic);
this._event.on(this._subTopic(topic).replace(/^\//g, ''), callback);
defer(done);
};
EventEmitter2Ascoltatore.prototype.publish = function (topic, message, options, done) {
this._raiseIfClosed();
debug("new message published to " + topic);
this._event.emit(this._pubTopic(topic).replace(/^\//g, ''), topic, message, options);
defer(done);
};
EventEmitter2Ascoltatore.prototype.unsubscribe = function unsubscribe(topic, callback, done) {
this._raiseIfClosed();
debug("deregistered subscriber for topic " + topic);
this._event.off(this._subTopic(topic).replace(/^\//g, ''), callback);
defer(done);
};
EventEmitter2Ascoltatore.prototype.close = function close(done) {
this._event.removeAllListeners();
this.emit("closed");
debug("closed");
defer(done);
};
util.aliasAscoltatore(EventEmitter2Ascoltatore.prototype);
/**
* Exports the EventEmitter2Ascoltatore.
*
* @api public
*/
module.exports = EventEmitter2Ascoltatore;