Skip to content

Instantly share code, notes, and snippets.

@Schniz
Last active November 19, 2024 15:29
Show Gist options
  • Save Schniz/d9c78c898d502ef101df373bb450e7a2 to your computer and use it in GitHub Desktop.
Save Schniz/d9c78c898d502ef101df373bb450e7a2 to your computer and use it in GitHub Desktop.
force sync jazz state
async function forceSync(account: Account) {
const { syncManager } = account._raw.core.node;
const peer = Object.values(syncManager.peers)[0];
if (!peer) {
throw new Error("no peer");
}
const values = Object.values(account._raw.core.node.coValues).flatMap((x) => {
if ("coValue" in x.state) {
return [x.state.coValue];
}
return [];
});
await Promise.all(values.map((value) => syncManager.syncCoValue(value)));
await Promise.all(
values.map((value) => {
return syncManager.waitForUploadIntoPeer(peer.id, value.id);
}),
);
console.log("synced.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment