Skip to content

Commit c6f3240

Browse files
committed
Update reads on readable events
1 parent 1874bf4 commit c6f3240

8 files changed

Lines changed: 27 additions & 23 deletions

File tree

examples/app3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function fetchRows(rs, cb) {
5252

5353
function onreadable() {
5454
/* jshint validthis:true */
55-
var chunk = this.read();
56-
if (chunk) {
55+
var chunk;
56+
while (null !== (chunk = this.read())) {
5757
rows.push(chunk);
5858
}
5959
}

examples/app7.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ function fetch(rs, cb) {
107107

108108
function read() {
109109
/* jshint validthis:true */
110-
var row = this.read();
111-
if (row) {
110+
var row;
111+
while (null !== (row = this.read())) {
112112
rows.push(row);
113113
}
114114
}

test/acceptance/db.Query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ describe('db', function () {
7373
readable.once('error', function onerror() {
7474
done(err);
7575
}).on('readable', function onreadable() {
76-
var chunk = this.read();
77-
if (chunk) {
76+
var chunk;
77+
while (null !== (chunk = this.read())) {
7878
rows = rows.concat(chunk);
7979
}
8080
}).once('end', function onend() {

test/lib.Lob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ describe('Lib', function () {
9595
var stream = lob.createReadStream();
9696
var chunks = [];
9797
stream.on('readable', function () {
98-
var chunk = stream.read();
99-
if (chunk) {
98+
var chunk;
99+
while (null !== (chunk = stream.read())) {
100100
chunks.push(chunk);
101101
}
102102
if (chunks.length === 3) {

test/lib.ResultSet.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ ConnectionMock.prototype.fetchNext = function fetchNext(options, cb) {
9393
function readSimpleStream(rs, stream, cb) {
9494
var chunks = [];
9595
stream.on('readable', function onreadable() {
96-
var chunk = stream.read();
97-
if (chunk !== null) {
98-
chunks.push(chunk);
99-
}
96+
var chunk;
97+
while (null !== (chunk = stream.read())) {
98+
chunks.push(chunk);
99+
}
100100
});
101101
rs.once('error', function onerror(err) {
102102
cb(err);

test/lib.ResultSetTransform.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ describe('Lib', function () {
120120
});
121121
var chunks = [];
122122
rst.on('readable', function () {
123-
var value = rst.read();
124-
if (value !== null) {
123+
var value;
124+
while ((value = rst.read()) !== null) {
125125
chunks.push(Buffer.from([value]));
126126
}
127127
});
@@ -143,8 +143,8 @@ describe('Lib', function () {
143143
});
144144
var chunks = [];
145145
rst.on('readable', function () {
146-
var value = rst.read();
147-
if (value !== null) {
146+
var value;
147+
while ((value = rst.read()) !== null) {
148148
chunks.push(Buffer.from(value));
149149
}
150150
});
@@ -167,8 +167,8 @@ describe('Lib', function () {
167167
});
168168
var chunks = [];
169169
rst.on('readable', function () {
170-
var value = rst.read();
171-
if (value !== null) {
170+
var value;
171+
while ((value = rst.read()) !== null) {
172172
chunks.push(Buffer.from(value));
173173
}
174174
});

test/lib.Stringifier.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ function testStringifier(chunks, rows, done) {
7373
stringifier.on('error', function (err) {
7474
done(err);
7575
}).on('readable', function () {
76-
var chunk = this.read();
77-
if (chunk) {
76+
var chunk;
77+
while (null !== (chunk = this.read())) {
7878
data += chunk;
7979
}
80-
}).on('finish', function () {
80+
}).on('end', function () {
8181
JSON.parse(data).should.eql(rows);
8282
done();
8383
});

test/util.index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ describe('Util', function () {
5757

5858
var chunks = [];
5959
readable.on('readable', function () {
60-
var chunk = this.read();
61-
if (chunk !== null) {
60+
var chunk;
61+
var emit = false;
62+
while (null !== (chunk = this.read())) {
6263
var value = chunk[0];
6364
chunks.unshift(value);
65+
emit = true;
66+
}
67+
if (emit) {
6468
emitData();
6569
}
6670
});

0 commit comments

Comments
 (0)