Skip to content

Conversation

@alexjg
Copy link
Owner

@alexjg alexjg commented Dec 4, 2025

This PR changes the Repo::connect API and adds some related features with two broad objectives:

  • Remove the need for users to spawn a task to run the Repo::connect future
  • Make it easier to explicitly wait for various events w.r.t a particular connection. Specifically
    • Waiting for a connection to be "live"
    • Waiting for a document to be synchronized with a particular connection

The main shape this change takes is that Repo::connect now synchronously returns Connection object, which has methods on it for awaiting handshake completion. The connection handling task is now spawned on the runtime used at construction instead of requiring the user to run it. There are also new APIs on DocHandle for monitoring connection states: DocHandle::peers, which returns the current state of connected peers for the given document and DocHandle::they_have_our_changes for waiting for the given connection to say they have received everything we have.

Problem: it is often necessary to wait for a connection to be running
before taking action, or to examine a connection to find out the peer ID
of the other end. Furthermore, driving connection futures returned by
`Repo::connect` is awkward and easy to forget.

Solution: Introduce a `Connection` abstraction which is immediately
(synchronously) returned by `Repo::connect` and represents the ongoing
state of the connection. This gives us a place to put APIs for
connection related actions such as waiting for the handshake to
complete. To achieve this we run the connection handling logic on the IO
loop, which removes the need for the user to drive a future returned by
`Repo::connect`.
@alexjg alexjg merged commit 793de8d into main Dec 5, 2025
1 check passed
@alexjg alexjg deleted the conn-rework branch December 5, 2025 23:58
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.

2 participants