refactor: use native Promise.withResolvers and extract a shared abort-race helper#1754
Merged
Merged
Conversation
…rt-race helper Node.js 22 ships `Promise.withResolvers` natively, so the local polyfill can go away (`lib` is bumped to ES2024 to match). The connect/login methods all repeated the same idiom: create a promise that rejects on signal abort, race pending work against it, and remove the abort listener in a `finally` block. This is now captured in a single `withAbortRace` helper. The helper also marks the abort rejection as handled, closing a small unhandled-rejection window when a signal aborts while no race is pending. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ReviewClean, well-scoped refactor — I traced every call site and the abort-race semantics are preserved exactly (listener add/remove lifecycle, signal check order, Code quality
Correctness
Test coverage
Minor / nit
Overall: a good, low-risk refactor that reduces duplication and closes a small edge case. Nice work. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1754 +/- ##
==========================================
- Coverage 80.64% 80.64% -0.01%
==========================================
Files 90 90
Lines 4913 4887 -26
Branches 923 923
==========================================
- Hits 3962 3941 -21
+ Misses 650 645 -5
Partials 301 301 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related cleanups in the connect/login codepath:
Use native
Promise.withResolvers. Node.js 22 (our minimum supported version) ships this natively, so the localwithResolverspolyfill can go away.tsconfig.json'slibis bumped from ES2022 to ES2024 to pick up the type definitions.Extract a shared abort-race helper. All of the async connect/login methods (
performTlsNegotiation,readPreloginResponse, the threeperformSentLogin7With*methods, andperformLoggedInSendingInitialSql) repeated the same idiom:This is now captured in a single
withAbortRace(signal, func)helper that passes thesignalAbortedpromise into the given function, so call sites that race it multiple times per invocation (the PRELOGIN read loop, the NTLM challenge loop) work unchanged.The helper also marks the abort rejection as handled, closing a small unhandled-rejection window that existed when a signal aborted while no
Promise.racewas currently pending against it.No behavior changes otherwise; listener add/remove lifecycles are identical.
🤖 Generated with Claude Code