FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

stream: allow stream to stay open after take by rluvaton · Pull Request #47023 · nodejs/node · GitHub

/ node Public

stream: allow stream to stay open after take - #47023

Closed
rluvaton wants to merge 18 commits into
nodejs:mainfrom
rluvaton:feat/allow_stream-to-stay-open-after-take-46980
Closed

stream: allow stream to stay open after take#47023
rluvaton wants to merge 18 commits into
nodejs:mainfrom
rluvaton:feat/allow_stream-to-stay-open-after-take-46980

Conversation

rluvaton commented Mar 9, 2023
edited
Loading

Copy link
Copy Markdown
Member

fix #46980

TODO

  • add tests
  • add docs

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

Comment on lines +401 to +403
if (options?.destroyStream != null) {
validateBoolean(options.destroyStream, 'options.destroyStream');
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe another name would be better? Not sure what though... @benjamingr

Comment thread lib/internal/streams/operators.js Outdated
Comment on lines 410 to 413
for await (const val of this.iterator({ destroyOnReturn: options?.destroyStream ?? true })) {
if (options?.signal?.aborted) {
throw new AbortError();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think that if the stream fails we should close the stream, WDYT @ronag ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mcollina any thoughts on your side?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

after thinking I think it should be closed on an error as in the iterator helpers proposal spec the underlying iterator should be closed when it failed

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for opening a PR! Can you please add a unit test?

mcollina commented Mar 9, 2023

Copy link
Copy Markdown
Member

Docs are also missing

rluvaton commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

Hey @mcollina I've added tests and docs :)

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 10, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 10, 2023

Copy link
Copy Markdown
Member Author

@mcollina is something holding this back from merging? Or we waiting for the TC39?

Copy link
Copy Markdown
Member

we have 48 hours grace period to allow for folks across the globe to review

mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 10, 2023
github-actions Bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Mar 10, 2023

Copy link
Copy Markdown
Contributor
Failed to start CI
- Validating Jenkins credentials
✔  Jenkins credentials valid
- Starting PR CI job
✘  Failed to start PR CI: 403 Forbidden
https://github.com/nodejs/node/actions/runs/4384604326

Copy link
Copy Markdown
Collaborator

Comment thread doc/api/stream.md Outdated
Co-authored-by: Debadree Chatterjee <debadree333@gmail.com>
Comment thread doc/api/stream.md Outdated
…fter-take-46980' into feat/allow_stream-to-stay-open-after-take-46980

debadree25 left a comment
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think you would need to remove the merge commit since supposedly it can cause issues with the tooling everything else is good!!

Copy link
Copy Markdown
Member Author

I think you would need to remove the merge commit since supposedly it can cause issues with the tooling everything else is good!!

aren't we using squash and merge?

Copy link
Copy Markdown
Contributor

I think you would need to remove the merge commit since supposedly it can cause issues with the tooling everything else is good!!

aren't we using squash and merge?

Ref: #46910 (comment)

benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think discussion has exhausted itself in the spec issue and I don't want to deviate from it until we proved we must

Copy link
Copy Markdown
Contributor

I don't think discussion has exhausted itself in the spec issue and I don't want to deviate from it until we proved we must

Should be add the blocked label for now then?

ronag added the blocked PRs that are blocked by other issues or PRs. label Mar 12, 2023

benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yeah sorry I meant to explicitly block and hit the wrong button

michaelficarra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think what you really want is a chunk (which will be proposed for inclusion in standard iterators in the future) or a nextN helper like

function nextN(iterator, n) {
  const result = [];
  const next = iterator.next;
  for (; n > 0; --n) {
    cont { done, value } = next.call(iterator);
    if (done) break;
    result.push(value);
  }
  return result;
}

Copy link
Copy Markdown
Member Author

@michaelficarra no problem but maybe could you update the proposal first so we won't have this back and forth

FYI I think nextN is better name than chunk

Copy link
Copy Markdown
Contributor

@rluvaton chunk is a different method than the nextN that I wrote. See tc39/proposal-iterator-helpers#71 (comment) or https://www.npmjs.com/package/chunk.

rluvaton commented Mar 16, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

@rluvaton chunk is a different method than the nextN that I wrote. See tc39/proposal-iterator-helpers#71 (comment) or npmjs.com/package/chunk.

@michaelficarra

Oh, after looking at chunk what I really want is nextN which is basically a non-closing take

Do you think that non-closing take will be added?

chunk is less what I want as:

  1. I don't want chunks I just want the x items and the rest left unchanged (like in the headers row from CSV file - explained more in the linked issue)
  2. The data is not evenly distributed
  3. It won't let me get X items without closing the stream, I would just get another iterator that emits in chunks which I can't exit as it will close

rluvaton commented Mar 16, 2023
edited
Loading

Copy link
Copy Markdown
Member Author

Having nextN as an operator that returns iterable would enable:

  • better chaining
  • better efficiency (no need to save the values in case we don't need - without .toArray())

Example of usages:

having it as an operator:

const responses = await topVisitedUrlsIterator
	.filter(noEmptyLine)
	.drop(1) // Header
	.nextN(8)
	.map(parseLine)
	.map(value => apiCall(value), { concurrency: 4 })
	.toArray();

having it as a static function:

const values = await nextN(
  topVisitedUrlsIterator
    .filter(noEmptyLine)
    .drop(1),
  8)
  .map(parseLine);

// How would I use the concurrency that we would have in the map?
const responses = concurrentMap(values, (value) => apiCall(value), 4);

rluvaton mentioned this pull request May 20, 2023
aduh95 added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Aug 8, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 10, 2023

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked PRs that are blocked by other issues or PRs. needs-ci PRs that need a full CI run. stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stream: Add option to Readable.take operator to not close the stream

9 participants


Back | FazBrowse Home | New Git URL