Browse files

Handle buffer better

Write to the buffer in .write if the buffer has data

Only emit connect after the buffer has emptied
  • Loading branch information...
1 parent 6792505 commit d9ed147c061df163ee77369c1feb975045b82480 @Raynos Raynos committed Aug 6, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 browser.js
View
4 browser.js
@@ -23,7 +23,7 @@ module.exports = function (uri, cb) {
stream.sock = sock;
stream.write = function (msg) {
- if (!ready) buffer.push(msg)
+ if (!ready || buffer.length) buffer.push(msg)
else sock.send(msg)
};
stream.end = function (msg) {
@@ -46,11 +46,11 @@ module.exports = function (uri, cb) {
sock.onopen = function () {
if (typeof cb === 'function') cb();
ready = true;
- stream.emit('connect')
buffer.forEach(function (msg) {
sock.send(msg);
});
buffer = [];
+ stream.emit('connect')
if (stream._ended) stream.end();
};
sock.onmessage = function (e) {

0 comments on commit d9ed147

Please sign in to comment.