Skip to content

refactor: build every bounded wait on the Socket from one BoundedWait - #334

Open
diegolmello wants to merge 1 commit into
mobilefrom
diegolmello/sdk-arch-waits
Open

refactor: build every bounded wait on the Socket from one BoundedWait#334
diegolmello wants to merge 1 commit into
mobilefrom
diegolmello/sdk-arch-waits

Conversation

@diegolmello

Copy link
Copy Markdown
Member

Proposed changes

The Socket hand-rolled the same wait six times — a settled flag, a setTimeout deadline, and a cleanup that removes listeners and clears the timer — in waitForClose, reopenNow, probe, waitForOpen, ping's unanswered-reply deadline, and send's response wait. Each copy re-derived the once-only rule, and one copy differed from the others.

All six now use a single BoundedWait: it ends exactly once (first settle, deadline, or cancel), releases whatever the wait attached before the promise settles, and clears its own timer.

One behavioural difference falls out of reopenNow. It used to assign this.reopenPromise only after the promise executor returned, so an open that arrived synchronously inside the executor deleted reopenPromise before it was ever set — leaving a resolved promise installed forever and every later reopenNow a no-op. The promise now exists before the connection is created, so the release deletes the field that was actually set. No pinned expectation changed.

Steps to reproduce

  • Not a user-visible fix; behaviour is locked by the existing DDP driver suite.
  • The full suite (184 tests), tsc on both projects, and oxlint pass unchanged.

Tests

  • BoundedWait resolves with the value it is settled with
  • BoundedWait rejects with the error it is failed with
  • BoundedWait keeps the first settle when a second follows
  • BoundedWait ends on its deadline
  • BoundedWait does not reach its deadline once it is settled
  • BoundedWait releases what it attached, once, when it settles
  • BoundedWait releases every release it was given
  • BoundedWait leaves the promise to another settler when it is cancelled

@diegolmello diegolmello reopened this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant