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

stream: implement finished() for ReadableStream and WritableStream #46205

Merged
merged 16 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! remove public property
  • Loading branch information
debadree25 committed Jan 15, 2023
commit 70630b330036b2fc3b6f2a08fad2b37c1d6a0403
3 changes: 2 additions & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {

const {
isBrandCheck,
kState,
} = require('internal/webstreams/util');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this will break readable-stream I think you need to inverse the dependency and have webstream require symbols from stream.

FYI @mcollina

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in having the symbols defined in internal/streams/util and webstreams requiring from there?

Copy link
Member

@ronag ronag Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we might even need to use a SymbolFor('nodejs.webstream.closed'). Similar to #45671.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so would try to do the following, define SymbolFor('nodejs.webstream.closed') in internal/streams/util and use that instead of storing closed in the kState?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have implemented this could you check?


const isReadableStream =
ronag marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -269,7 +270,7 @@ function eos(stream, options, callback) {

function eosWeb(stream, opts, callback) {
RaisinTen marked this conversation as resolved.
Show resolved Hide resolved
PromisePrototypeThen(
stream.streamClosed,
stream[kState].streamClosed,
() => callback.call(stream),
(err) => callback.call(stream, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to call the callback with a process.nextTick

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood updating

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this to properly use process.nextTick

);
Expand Down
6 changes: 0 additions & 6 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ class ReadableStream {
return isReadableStreamLocked(this);
}

get streamClosed() {
if (!isReadableStream(this))
throw new ERR_INVALID_THIS('ReadableStream');
return this[kState].streamClosed.promise;
}

/**
* @param {any} [reason]
* @returns { Promise<void> }
Expand Down
6 changes: 0 additions & 6 deletions lib/internal/webstreams/writablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ class WritableStream {
return isWritableStreamLocked(this);
}

get streamClosed() {
if (!isWritableStream(this))
throw new ERR_INVALID_THIS('WritableStream');
return this[kState].streamClosed.promise;
}

/**
* @param {any} reason
* @returns {Promise<void>}
Expand Down