Permalink
Browse files

allow continuation to come through in streaming responses correctly

  • Loading branch information...
1 parent 07f1063 commit 8396518875807a06a802fa61d5b225ff102be8b9 @nlf committed Feb 3, 2014
Showing with 14 additions and 13 deletions.
  1. +1 −1 README.md
  2. +8 −3 index.js
  3. +5 −9 test/client-test.js
View
@@ -280,7 +280,7 @@ client.put(request, function (err, reply) {
This method removes a key from a bucket. Specify the bucket and the key:
```javascript
-client.del({ bucket: 'test', song: 'thriller' }, function (err, reply) {
+client.del({ bucket: 'songs', key: 'thriller' }, function (err, reply) {
console.log('it was totally overrated.');
});
```
View
@@ -23,7 +23,7 @@ function RiakPBC(options) {
}
RiakPBC.prototype._processMessage = function (data) {
- var response, messageCode, err;
+ var response, messageCode, err, done;
messageCode = riakproto.codes['' + data[0]];
response = this.translator.decode(messageCode, data.slice(1));
@@ -46,15 +46,20 @@ RiakPBC.prototype._processMessage = function (data) {
}
}
- if (!response.done || response.continuation) {
+ if (response.done) {
+ done = true;
+ delete response.done;
+ }
+
+ if (Object.keys(response).length) {
this.task.stream.write(response);
}
if (this.task.callback) {
this.reply = _merge(this.reply, response);
}
- if (response.done || !this.task.expectMultiple || messageCode === 'RpbErrorResp') {
+ if (done || !this.task.expectMultiple || messageCode === 'RpbErrorResp') {
this.task.stream.end();
if (this.task.callback) {
View
@@ -736,17 +736,13 @@ describe('Client test', function () {
});
stream.on('data', function (reply) {
expect(reply).to.exist;
- if (reply && reply.keys) {
- results.keys = (results.keys || []).concat(reply.keys);
- }
- if (reply && reply.continuation) {
- results.continuation = reply.continuation;
- }
+ if (reply.continuation) results.continuation = reply.continuation;
+ results.keys = (results.keys || []).concat(reply.keys);
});
- stream.on('end', function () {
+ stream.on('end', function (reply) {
expect(results.keys, 'keys not set in results').to.exist;
- expect(results.continuation, 'continuation not set in results').to.exist;
- expect(results.keys.length).to.equal(2);
+ expect(results.keys.length).to.equal(3);
+ expect(results.continuation, 'continuation not set in end reply').to.exist;
done();
});
});

0 comments on commit 8396518

Please sign in to comment.