Skip to content

Commit

Permalink
Resolve issue #38 & #37
Browse files Browse the repository at this point in the history
fix readAsPromised - stuck if stream alredy "end" #36 (#38)
fix setPromiseItem - no wait input promise !! #37

Co-authored-by: Vyacheslav Skakun <[email protected]>
  • Loading branch information
SlavikPr and Vyacheslav Skakun authored Jan 27, 2024
1 parent eaca536 commit 35dfefe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/JsonStreamStringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ function readAsPromised(stream, size) {
const value = stream.read(size);
if (value === null) {
return new Promise((resolve, reject) => {
if (stream.readableEnded) {
resolve(null);
return;
}
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
Expand Down Expand Up @@ -358,11 +362,13 @@ export class JsonStreamStringify extends Readable {
this.item = {
async read() {
if (read) return;
read = true;
input.then((v) => that.setItem(v, parent, key), (err) => {
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
});
}
},
};
}
Expand Down

0 comments on commit 35dfefe

Please sign in to comment.