forked from kb18519142009/android_interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
51 lines (40 loc) · 1.12 KB
/
middleware.js
File metadata and controls
51 lines (40 loc) · 1.12 KB
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
var dnode = require('../');
var test = require('tape');
test('middleware', function (t) {
t.plan(5);
var tf = setTimeout(function () {
t.fail('never finished');
}, 1000);
var tr = setTimeout(function () {
t.fail('never ready');
}, 1000);
var tc = setTimeout(function () {
t.fail('connection not ready');
}, 1000);
var server = dnode(function (client, conn) {
var self = this;
t.ok(!conn.zing);
t.ok(!client.moo);
conn.on('remote', function () {
clearTimeout(tr);
t.ok(conn.zing);
t.ok(self.moo);
});
this.baz = 42;
});
server.on('local', function (client, conn) {
conn.zing = true;
});
server.on('local', function (client, conn) {
client.moo = true;
conn.on('remote', function () {
clearTimeout(tc);
});
});
var client = dnode();
client.on('remote', function (remote, conn) {
clearTimeout(tf);
t.ok(remote.baz);
});
server.pipe(client).pipe(server);
});