Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit d9ed147c061df163ee77369c1feb975045b82480 1 parent 6792505
@Raynos Raynos authored
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) {
Please sign in to comment.
Something went wrong with that request. Please try again.