08-27-周三_17-09-29
This commit is contained in:
30
node_modules/dnode/test/bidirectional.js
generated
vendored
Normal file
30
node_modules/dnode/test/bidirectional.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var dnode = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('bidirectional', function (t) {
|
||||
t.plan(3);
|
||||
|
||||
var server = dnode(function (client) {
|
||||
this.timesX = function (n,f) {
|
||||
t.equal(n, 3, "timesX's n == 3");
|
||||
|
||||
client.x(function (x) {
|
||||
t.equal(x, 20, 'client.x == 20');
|
||||
f(n * x);
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
var client = dnode({
|
||||
x : function (f) { f(20) }
|
||||
});
|
||||
client.on('remote', function (remote) {
|
||||
remote.timesX(3, function (res) {
|
||||
t.equal(res, 60, 'result of 20 * 3 == 60');
|
||||
client.end();
|
||||
server.end();
|
||||
});
|
||||
});
|
||||
|
||||
client.pipe(server).pipe(client);
|
||||
});
|
Reference in New Issue
Block a user