Refactor DB code to use promises
This commit is contained in:
1 parent
3169e829e7
commit
58488ebc3d
12 files changed
+3814
-1054
No files matched your search
+6
-1
@@ -1473,10 +1473,15 @@ async function listenerAsync(
|
||||
|
||||
const chunks: Buffer[] = [];
|
||||
try {
|
||||
let readableEnded = false;
|
||||
stream.on("end", () => {
|
||||
readableEnded = true;
|
||||
});
|
||||
for await (const chunk of stream) chunks.push(chunk);
|
||||
// In Node versions prior to 15, the stream will not emit an error if the
|
||||
// connection is closed before the stream is finished.
|
||||
if (!stream.readableEnded) throw new Error("Connection closed");
|
||||
// For Node 12.9+ we can just use stream.readableEnded
|
||||
if (!readableEnded) throw new Error("Connection closed");
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user