Permalink
Browse files

build

  • Loading branch information...
1 parent 3af9437 commit 3862f0c4c8787882c178cc17ebb904e4c88fcd32 @contra contra committed Aug 11, 2012
Showing with 38 additions and 18 deletions.
  1. +11 −2 examples/add/vein.js
  2. +15 −13 test/server.coffee
  3. +11 −2 vein.js
  4. +1 −1 vein.min.js
View
@@ -2647,7 +2647,14 @@ function ws () {
},
start: function() {
this.services = {};
- return this.callbacks = {};
+ this.callbacks = {};
+ return this.connected = false;
+ },
+ ready: function(fn) {
+ if (this.connected === true) {
+ return fn(this.services);
+ }
+ return this.on('ready', fn);
},
inbound: function(socket, msg, done) {
try {
@@ -2700,6 +2707,7 @@ function ws () {
throw err;
},
close: function(socket, reason) {
+ this.connected = false;
return this.emit('close', reason);
},
message: function(socket, msg) {
@@ -2715,6 +2723,7 @@ function ws () {
k = _ref1[_i];
this[k] = this.getSender(socket, k);
}
+ this.connected = true;
return this.emit('ready', this.services);
}
},
@@ -2730,7 +2739,7 @@ function ws () {
id: id,
service: service,
args: args,
- cookies: {}
+ cookies: _this.cookie()
});
};
},
View
@@ -48,7 +48,7 @@ describe 'Vein', ->
res.reply numOne * numTwo
client = getClient serv
- client.on 'ready', (services) ->
+ client.ready (services) ->
client.connected.should.be.true
services.should.eql ['test']
client.test 5, 6, (num) ->
@@ -63,7 +63,7 @@ describe 'Vein', ->
res.reply 'goyta'
client = getClient serv
- client.on 'ready', (services) ->
+ client.ready (services) ->
client.test ->
client.cookie('result').should.equal 'oi'
serv.destroy()
@@ -86,21 +86,23 @@ describe 'Vein', ->
serv.add 'test', (res) -> res.reply()
client = getClient serv
- client.on 'ready', (services) ->
+ client.ready (services) ->
client.test ->
called.should.equal true
serv.destroy()
done()
- describe 'multiple clients', ->
+describe 'client', ->
+ it 'should work on multiple clients', (done) ->
serv = getServer()
- it 'should work', (done) ->
- client = getClient serv
- client.on 'ready', (services) ->
- client.ready (services) ->
- done()
+ client = getClient serv
+ client.ready (services) ->
+ client2 = getClient serv
+ client2.ready (services) -> done()
- it 'should work on the second client', (done) ->
- client = getClient serv
- client.on 'ready', (services) ->
- done()
+ it 'should disconnect before ready', (done) ->
+ serv = getServer()
+ client = getClient serv
+ client.ready ->
+ client.disconnect()
+ done()
View
13 vein.js
@@ -2647,7 +2647,14 @@ function ws () {
},
start: function() {
this.services = {};
- return this.callbacks = {};
+ this.callbacks = {};
+ return this.connected = false;
+ },
+ ready: function(fn) {
+ if (this.connected === true) {
+ return fn(this.services);
+ }
+ return this.on('ready', fn);
},
inbound: function(socket, msg, done) {
try {
@@ -2700,6 +2707,7 @@ function ws () {
throw err;
},
close: function(socket, reason) {
+ this.connected = false;
return this.emit('close', reason);
},
message: function(socket, msg) {
@@ -2715,6 +2723,7 @@ function ws () {
k = _ref1[_i];
this[k] = this.getSender(socket, k);
}
+ this.connected = true;
return this.emit('ready', this.services);
}
},
@@ -2730,7 +2739,7 @@ function ws () {
id: id,
service: service,
args: args,
- cookies: {}
+ cookies: _this.cookie()
});
};
},
Oops, something went wrong.

0 comments on commit 3862f0c

Please sign in to comment.