Skip to content

Commit

Permalink
Update reads on readable events
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpenev-s committed Mar 25, 2019
1 parent 1874bf4 commit c6f3240
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/app3.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function fetchRows(rs, cb) {

function onreadable() {
/* jshint validthis:true */
var chunk = this.read();
if (chunk) {
var chunk;
while (null !== (chunk = this.read())) {
rows.push(chunk);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/app7.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function fetch(rs, cb) {

function read() {
/* jshint validthis:true */
var row = this.read();
if (row) {
var row;
while (null !== (row = this.read())) {
rows.push(row);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/db.Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe('db', function () {
readable.once('error', function onerror() {
done(err);
}).on('readable', function onreadable() {
var chunk = this.read();
if (chunk) {
var chunk;
while (null !== (chunk = this.read())) {
rows = rows.concat(chunk);
}
}).once('end', function onend() {
Expand Down
4 changes: 2 additions & 2 deletions test/lib.Lob.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ describe('Lib', function () {
var stream = lob.createReadStream();
var chunks = [];
stream.on('readable', function () {
var chunk = stream.read();
if (chunk) {
var chunk;
while (null !== (chunk = stream.read())) {
chunks.push(chunk);
}
if (chunks.length === 3) {
Expand Down
8 changes: 4 additions & 4 deletions test/lib.ResultSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ ConnectionMock.prototype.fetchNext = function fetchNext(options, cb) {
function readSimpleStream(rs, stream, cb) {
var chunks = [];
stream.on('readable', function onreadable() {
var chunk = stream.read();
if (chunk !== null) {
chunks.push(chunk);
}
var chunk;
while (null !== (chunk = stream.read())) {
chunks.push(chunk);
}
});
rs.once('error', function onerror(err) {
cb(err);
Expand Down
12 changes: 6 additions & 6 deletions test/lib.ResultSetTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ describe('Lib', function () {
});
var chunks = [];
rst.on('readable', function () {
var value = rst.read();
if (value !== null) {
var value;
while ((value = rst.read()) !== null) {
chunks.push(Buffer.from([value]));
}
});
Expand All @@ -143,8 +143,8 @@ describe('Lib', function () {
});
var chunks = [];
rst.on('readable', function () {
var value = rst.read();
if (value !== null) {
var value;
while ((value = rst.read()) !== null) {
chunks.push(Buffer.from(value));
}
});
Expand All @@ -167,8 +167,8 @@ describe('Lib', function () {
});
var chunks = [];
rst.on('readable', function () {
var value = rst.read();
if (value !== null) {
var value;
while ((value = rst.read()) !== null) {
chunks.push(Buffer.from(value));
}
});
Expand Down
6 changes: 3 additions & 3 deletions test/lib.Stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ function testStringifier(chunks, rows, done) {
stringifier.on('error', function (err) {
done(err);
}).on('readable', function () {
var chunk = this.read();
if (chunk) {
var chunk;
while (null !== (chunk = this.read())) {
data += chunk;
}
}).on('finish', function () {
}).on('end', function () {
JSON.parse(data).should.eql(rows);
done();
});
Expand Down
8 changes: 6 additions & 2 deletions test/util.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ describe('Util', function () {

var chunks = [];
readable.on('readable', function () {
var chunk = this.read();
if (chunk !== null) {
var chunk;
var emit = false;
while (null !== (chunk = this.read())) {
var value = chunk[0];
chunks.unshift(value);
emit = true;
}
if (emit) {
emitData();
}
});
Expand Down

0 comments on commit c6f3240

Please sign in to comment.