Skip to content

Commit a7f1677

Browse files
Marcus PousetteMarcus Pousette
authored andcommitted
Add reliable inbound sync controller
1 parent 91ca885 commit a7f1677

5 files changed

Lines changed: 757 additions & 0 deletions

File tree

.changeset/clean-inbound-sync.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@treecrdt/sync': minor
3+
---
4+
5+
Add an inbound sync helper with aggregate per-target failures, cancelling timeouts, and live filter subscriptions.

packages/treecrdt-sync/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ Use `addTarget` only when the transport was already attached to the same `localP
3434
dedupes standard TreeCRDT `Operation` values by `meta.id`. Pass `opKey` only for a custom op shape
3535
or custom coalescing behavior.
3636

37+
## Multi-peer inbound sync
38+
39+
Use `createInboundSync` to reconcile or subscribe the same filters across registered peer
40+
transports. `syncOnce` resolves only when every requested peer/filter target succeeds. If any target
41+
fails, it finishes the remaining targets and rejects with `InboundSyncAggregateError`; its
42+
`failures` entries identify the `peerId`, `filter`, and original `error` for each failed target.
43+
44+
```ts
45+
const inbound = createInboundSync({ localPeer: peer });
46+
inbound.addPeer('remote:server', websocketTransport);
47+
48+
await inbound.syncOnce({ all: {} }, { syncTimeoutMs: 10_000 });
49+
inbound.subscribe([{ children: { parent: rootId } }]);
50+
```
51+
52+
A `syncTimeoutMs` deadline aborts the underlying `SyncPeer.syncOnce` session, so reconciliation does
53+
not keep sending after the caller receives the timeout failure.
54+
3755
## When not to
3856

3957
- You only need the protocol types and `SyncPeer` (use **`@treecrdt/sync-protocol`**).

0 commit comments

Comments
 (0)