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

refactor: reduce code duplication in gin_helper::Promise #43716

Merged
merged 3 commits into from
Sep 17, 2024

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Sep 13, 2024

Description of Change

Refactor some parts of node_helper::Promise to avoid code repetition:

  • There were five methods with identical handle/microtask/context scopes setup before doing v8::Promise work. This PR extracts that setup into a new SettleScope struct, borrowing the idea from SpellCheckScope.

  • There were three methods with identical logic to decide whether to settle the promise immediately or to post it as a task. This PR extracts that logic into a new protected static method, PromiseBase::GetTaskRunner(). This has a happy side-effect of decoupling promise.h from the content module, which is good because about 80 files include promise.h.

  • Side-cleanup: PromiseBase::ResolvePromise() isn't a templated function, so its implementation can be moved from the header into the cc file.

  • There are a handful of unrelated .cc and .h files that need new #include lines because they are directly using API that used to be indirectly included via promise.h

Checklist

Release Notes

Notes: none.

@ckerr ckerr added semver/patch backwards-compatible bug fixes target/33-x-y PR should also be added to the "33-x-y" branch. labels Sep 13, 2024
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Sep 13, 2024
@ckerr ckerr self-assigned this Sep 13, 2024
@ckerr ckerr marked this pull request as draft September 14, 2024 00:49
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Sep 14, 2024
@ckerr ckerr marked this pull request as ready for review September 15, 2024 01:19
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Sep 15, 2024
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Sep 16, 2024
@ckerr ckerr removed their assignment Sep 16, 2024
@codebytere codebytere self-requested a review September 16, 2024 09:32
Copy link
Contributor

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

Nice! LGTM

@ckerr ckerr merged commit b6bf277 into main Sep 17, 2024
51 checks passed
@ckerr ckerr deleted the refactor/dry-promise branch September 17, 2024 04:08
Copy link

release-clerk bot commented Sep 17, 2024

No Release Notes

@trop
Copy link
Contributor

trop bot commented Sep 17, 2024

I was unable to backport this PR to "33-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/33-x-y and removed target/33-x-y PR should also be added to the "33-x-y" branch. labels Sep 17, 2024
ckerr added a commit that referenced this pull request Sep 18, 2024
* refactor: move scope scaffolding into SettletScope

idea stolen from SpellCheckScope

* refactor: move impl of PromiseBase::RejectPromise() to the cc file

* chore: remove unused #include
@trop
Copy link
Contributor

trop bot commented Sep 18, 2024

@ckerr has manually backported this PR to "33-x-y", please check out #43778

codebytere added a commit that referenced this pull request Sep 19, 2024
…3778)

refactor: reduce code duplication in gin_helper::Promise (#43716)

* refactor: move scope scaffolding into SettletScope

idea stolen from SpellCheckScope

* refactor: move impl of PromiseBase::RejectPromise() to the cc file

* chore: remove unused #include

Co-authored-by: Shelley Vohr <[email protected]>
@trop trop bot removed the in-flight/33-x-y label Sep 19, 2024
@trop trop bot added the merged/33-x-y PR was merged to the "33-x-y" branch. label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/33-x-y PR was merged to the "33-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants