Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix undefined proto errors by buffering proto.handle calls

  • Loading branch information...
commit 3aed87300c9fe3035b4bc81c52501477ac1783f1 1 parent 9e9efff
@substack authored
Showing with 16 additions and 4 deletions.
  1. +15 −3 lib/dnode.js
  2. +1 −1  package.json
View
18 lib/dnode.js
@@ -28,6 +28,10 @@ function dnode (cons, opts) {
if (self._ended) return;
self.proto = self._createProto();
self.proto.start();
+
+ (self._handleQueue || []).forEach(function (row) {
+ self.handle(row);
+ });
});
}
@@ -98,7 +102,7 @@ dnode.prototype.write = function (buf) {
j = i + 1;
- self.proto.handle(row);
+ self.handle(row);
self._bufs = [];
}
}
@@ -108,7 +112,7 @@ dnode.prototype.write = function (buf) {
else if (buf && typeof buf === 'object') {
// .isBuffer() without the Buffer
// Use self to pipe JSONStream.parse() streams.
- self.proto.handle(buf);
+ self.handle(buf);
}
else {
if (typeof buf !== 'string') buf = String(buf);
@@ -119,7 +123,7 @@ dnode.prototype.write = function (buf) {
try { row = json.parse(self._line) }
catch (err) { return self.end() }
- self.proto.handle(row);
+ self.handle(row);
self._line = '';
}
else self._line += buf.charAt(i)
@@ -127,6 +131,14 @@ dnode.prototype.write = function (buf) {
}
};
+dnode.prototype.handle = function (row) {
+ if (!this.proto) {
+ if (!this._handleQueue) this._handleQueue = [];
+ this._handleQueue.push(row);
+ }
+ else this.proto.handle(row);
+};
+
dnode.prototype.end = function () {
if (this._ended) return;
this._ended = true;
View
2  package.json
@@ -1,6 +1,6 @@
{
"name" : "dnode",
- "version" : "1.0.0",
+ "version" : "1.0.1",
"description" : "freestyle rpc",
"main" : "./index.js",
"keywords" : [
Please sign in to comment.
Something went wrong with that request. Please try again.