-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
68 lines (45 loc) · 1.33 KB
/
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
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
var EventEmitter = require('events').EventEmitter;
var inherits = require('util').inherits;
var WriteEmitter = require('./write_emitter');
var ReadEmitter = require('./read_emitter');
module.exports =
function createDuplexEmitter(stream) {
return new DuplexEmitter(stream);
};
function DuplexEmitter(stream) {
EventEmitter.call(this);
this.read = this.readEmitter = ReadEmitter(stream);
this.write = this.writeEmitter = WriteEmitter(stream);
this.write.on('error', onError.bind(this));
}
inherits(DuplexEmitter, EventEmitter);
/// addListener and on
DuplexEmitter.prototype.addListener =
DuplexEmitter.prototype.on =
function addListener(event, listener) {
return this.read.on(event, listener);
};
/// once
DuplexEmitter.prototype.once =
function once(event, listener) {
return this.read.once(event, listener);
};
/// removeListener
DuplexEmitter.prototype.removeListener =
function removeListener(event, listener) {
return this.read.removeListener(event, listener);
};
/// removeAllListeners
DuplexEmitter.prototype.removeAllListeners =
function removeAllListeners() {
return this.read.removeAllListeners.apply(this.read, arguments);
};
/// read_emitter
DuplexEmitter.prototype.emit =
function emit() {
return this.write.emit.apply(this.write, arguments);
};
// onError
function onError(err) {
this.emit('error', err);
}