Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node 18 (based on #711) #2389

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Query extends Command {
});
this.on('end', () => {
stream.push(null); // pushing null, indicating EOF
stream.emit('close'); // notify readers that query has completed
setImmediate(() => stream.emit('close')); // notify readers that query has completed
});
this.on('fields', fields => {
stream.emit('fields', fields); // replicate old emitter
Expand Down
8 changes: 7 additions & 1 deletion test/integration/connection/test-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const assert = require('assert');
let rows;
const rows1 = [];
const rows2 = [];
const rows3 = [];

connection.query(
[
Expand Down Expand Up @@ -45,7 +46,7 @@ connection.execute(
}
}
);
connection.execute('SELECT * FROM announcements', (err, _rows) => {
connection.execute('SELECT * FROM announcements', async (err, _rows) => {
rows = _rows;
const s1 = connection.query('SELECT * FROM announcements').stream();
s1.on('data', row => {
Expand All @@ -60,10 +61,15 @@ connection.execute('SELECT * FROM announcements', (err, _rows) => {
connection.end();
});
});
const s3 = connection.query('SELECT * FROM announcements').stream();
for await (const row of s3) {
rows3.push(row);
}
});

process.on('exit', () => {
assert.deepEqual(rows.length, 2);
assert.deepEqual(rows, rows1);
assert.deepEqual(rows, rows2);
assert.deepEqual(rows, rows3);
});
Loading