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

lib: refactor project to use Promise.withResolvers #54836

Merged
merged 2 commits into from
Oct 19, 2024

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 7, 2024

Node.js v22+ supports Promise.withResolvers(). Let's use them!

@anonrig anonrig added dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. labels Sep 7, 2024
@anonrig anonrig requested a review from aduh95 September 7, 2024 17:17
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/streams
  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Sep 7, 2024
Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

After all these years - this is still a bad API but we might as well use the official one :D

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 7, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 7, 2024
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 7, 2024
Copy link
Member

@atlowChemi atlowChemi left a comment

Choose a reason for hiding this comment

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

@anonrig could this have any impact on pref?
Should any benchmarks be run?

@RedYetiDev RedYetiDev added the promises Issues and PRs related to ECMAScript promises. label Sep 7, 2024
@anonrig
Copy link
Member Author

anonrig commented Sep 7, 2024

@anonrig could this have any impact on pref?

Should any benchmarks be run?

I think it will improve performance but I'm not sure. Once the tests pass, let's have a benchmark ci just to be sure.

@RedYetiDev RedYetiDev added the needs-benchmark-ci PR that need a benchmark CI run. label Sep 7, 2024
@jasnell
Copy link
Member

jasnell commented Sep 7, 2024

PromiseWithResolvers isn't in primordials yet, is it?

@anonrig
Copy link
Member Author

anonrig commented Sep 7, 2024

PromiseWithResolvers isn't in primordials yet, is it?

It seems like it can be removed by a v8 flag: https://github.com/v8/v8/blob/3b12a031d2293acf01872e213473c8657671c8db/src/init/bootstrapper.cc#L5585

@anonrig anonrig marked this pull request as draft September 7, 2024 22:27
@aduh95
Copy link
Contributor

aduh95 commented Sep 7, 2024

We should probably wait for 20.x to be in maintenance so it does not create conflicts when backporting other PRs (we could also wait for V8 to drop the flag, but we don't officially support running Node.js with undocumented flags, so that's not a blocker)

@jasnell
Copy link
Member

jasnell commented Sep 8, 2024

@anonrig ... I see you marked this author ready but the PR is still a draft. Going to remove the label for now until you confirm this is ready.

@jasnell jasnell removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 8, 2024
@jasnell
Copy link
Member

jasnell commented Sep 8, 2024

We should probably wait for 20.x to be in maintenance so it does not create conflicts when backporting other PRs (we could also wait for V8 to drop the flag, but we don't officially support running Node.js with undocumented flags, so that's not a blocker)

Alternatively, if we choose to backport this, we could also choose to polyfill Promise.withResolvers() in the older release lines.

@aduh95
Copy link
Contributor

aduh95 commented Sep 8, 2024

We should probably wait for 20.x to be in maintenance so it does not create conflicts when backporting other PRs (we could also wait for V8 to drop the flag, but we don't officially support running Node.js with undocumented flags, so that's not a blocker)

Alternatively, if we choose to backport this, we could also choose to polyfill Promise.withResolvers() in the older release lines.

We've decided that any change to globally available APIs would be semver-major in #54330 (I mean it hasn't landed yet, but it already has your approval 😅), so backporting to v20.x is a no-go.

@anonrig anonrig force-pushed the get-rid-of-deferred-promise branch 2 times, most recently from 0c08b61 to c69b907 Compare September 8, 2024 14:53
@anonrig anonrig marked this pull request as ready for review September 8, 2024 14:53
@ljharb
Copy link
Member

ljharb commented Sep 8, 2024

If it’s a correct polyfill, why does it matter which it is?

@anonrig
Copy link
Member Author

anonrig commented Sep 8, 2024

@aduh95 We already have polyfills in primordials

// Define Symbol.dispose and Symbol.asyncDispose
// Until these are defined by the environment.
// TODO(MoLow): Remove this polyfill once Symbol.dispose and Symbol.asyncDispose are available in V8.
primordials.SymbolDispose ??= primordials.SymbolFor('nodejs.dispose');
primordials.SymbolAsyncDispose ??= primordials.SymbolFor('nodejs.asyncDispose');

Copy link

codecov bot commented Sep 8, 2024

Codecov Report

Attention: Patch coverage is 96.72131% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.39%. Comparing base (7ae193d) to head (df1b7e5).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/fs/watchers.js 66.66% 1 Missing ⚠️
lib/internal/webstreams/adapters.js 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54836      +/-   ##
==========================================
- Coverage   88.40%   88.39%   -0.02%     
==========================================
  Files         653      653              
  Lines      187600   187585      -15     
  Branches    36117    36120       +3     
==========================================
- Hits       165854   165821      -33     
- Misses      14974    14981       +7     
- Partials     6772     6783      +11     
Files with missing lines Coverage Δ
lib/child_process.js 97.72% <100.00%> (ø)
lib/internal/abort_controller.js 98.05% <100.00%> (ø)
lib/internal/blob.js 99.80% <100.00%> (ø)
lib/internal/streams/duplexify.js 96.56% <100.00%> (ø)
lib/internal/test_runner/harness.js 92.67% <100.00%> (ø)
lib/internal/test_runner/runner.js 88.92% <100.00%> (ø)
lib/internal/test_runner/test.js 96.98% <100.00%> (ø)
lib/internal/test_runner/utils.js 56.67% <100.00%> (ø)
lib/internal/util.js 97.06% <ø> (+0.06%) ⬆️
lib/internal/webstreams/readablestream.js 98.32% <100.00%> (ø)
... and 5 more

... and 22 files with indirect coverage changes

@aduh95
Copy link
Contributor

aduh95 commented Sep 8, 2024

We already have polyfills in primordials

And we shouldn't – especially the Symbol.[async]dispose are not actual polyfills. I can move them in another PR.

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

LGTM (but I agree with the moving of the polyfill)

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 9, 2024
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the blocked PRs that are blocked by other issues or PRs. label Sep 25, 2024
@aduh95
Copy link
Contributor

aduh95 commented Sep 25, 2024

Blocked on #55115

@aduh95 aduh95 removed the blocked PRs that are blocked by other issues or PRs. label Oct 4, 2024
@aduh95
Copy link
Contributor

aduh95 commented Oct 17, 2024

This needs a rebase.

anonrig and others added 2 commits October 18, 2024 10:58
# Conflicts:
#	lib/internal/blob.js
#	lib/internal/test_runner/harness.js
#	lib/internal/test_runner/runner.js
#	test/parallel/test-runner-run-watch.mjs
#	test/parallel/test-runner-watch-mode-complex.mjs
#	test/parallel/test-runner-watch-mode.mjs
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Oct 18, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 18, 2024
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 merged commit bb8cc65 into nodejs:main Oct 19, 2024
63 checks passed
@aduh95
Copy link
Contributor

aduh95 commented Oct 19, 2024

Landed in bb8cc65

aduh95 pushed a commit that referenced this pull request Oct 19, 2024
PR-URL: #54836
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
@aduh95 aduh95 mentioned this pull request Oct 24, 2024
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
PR-URL: nodejs#54836
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. lib / src Issues and PRs related to general changes in the lib or src directory. needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. promises Issues and PRs related to ECMAScript promises.
Projects
None yet
Development

Successfully merging this pull request may close these issues.