This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathnested.js
More file actions
executable file
·50 lines (43 loc) · 1.68 KB
/
nested.js
File metadata and controls
executable file
·50 lines (43 loc) · 1.68 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
var dnode = require('../');
var test = require('tap').test;
test('nested', function (t) {
t.plan(4);
var port = Math.floor(Math.random() * 40000 + 10000);
var EventEmitter = require('events').EventEmitter;
var server1 = dnode({
timesTen : function (n,reply) { reply(n * 10) }
}).listen(port);
var server2 = dnode({
timesTwenty : function (n,reply) { reply(n * 20) }
}).listen(port + 1);
var moo = new EventEmitter;
// Don't worry, real code does't look like this:
server1.on('ready', function () {
server2.on('ready', function () {
dnode.connect(port, function (remote1, conn1) {
dnode.connect(port + 1, function (remote2, conn2) {
moo.on('hi', function (x) {
remote1.timesTen(x, function (res) {
t.equal(res, 5000, 'emitted value times ten');
remote2.timesTwenty(res, function (res2) {
t.equal(res2, 100000, 'result times twenty');
conn1.end(); conn2.end();
server1.close(); server2.close();
t.end();
});
});
});
remote2.timesTwenty(5, function (n) {
t.equal(n, 100);
remote1.timesTen(0.1, function (n) {
t.equal(n, 1);
});
});
});
});
});
});
setTimeout(function() {
moo.emit('hi', 500);
}, 200);
});