mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 01:29:31 +08:00
feat(nbstore): remove async on connection api (#9187)
We should not use async on `connect` and `disconnect`, for `WebSocketConnection` will never connect when offline. We should handle the connection status of each storage in sync, using the `connection.waitForConnect` This PR also puts the connection reference count on the `connect` and disconnect`
This commit is contained in:
@@ -23,7 +23,9 @@ test('doc', async () => {
|
||||
type: 'workspace',
|
||||
});
|
||||
|
||||
await docStorage.connect();
|
||||
docStorage.connect();
|
||||
|
||||
await docStorage.waitForConnected();
|
||||
|
||||
const frontend1 = new DocFrontend(docStorage, null);
|
||||
frontend1.start();
|
||||
@@ -66,8 +68,11 @@ test('awareness', async () => {
|
||||
type: 'workspace',
|
||||
});
|
||||
|
||||
await storage1.connect();
|
||||
await storage2.connect();
|
||||
storage1.connect();
|
||||
storage2.connect();
|
||||
|
||||
await storage1.waitForConnected();
|
||||
await storage2.waitForConnected();
|
||||
|
||||
// peer a
|
||||
const docA = new YDoc({ guid: 'test-doc' });
|
||||
|
||||
@@ -44,9 +44,13 @@ test('doc', async () => {
|
||||
const peerB = new SpaceStorage([peerBDoc]);
|
||||
const peerC = new SpaceStorage([peerCDoc]);
|
||||
|
||||
await peerA.connect();
|
||||
await peerB.connect();
|
||||
await peerC.connect();
|
||||
peerA.connect();
|
||||
peerB.connect();
|
||||
peerC.connect();
|
||||
|
||||
await peerA.waitForConnected();
|
||||
await peerB.waitForConnected();
|
||||
await peerC.waitForConnected();
|
||||
|
||||
await peerA.get('doc').pushDocUpdate({
|
||||
docId: 'doc1',
|
||||
@@ -121,6 +125,18 @@ test('blob', async () => {
|
||||
type: 'workspace',
|
||||
});
|
||||
|
||||
const peerA = new SpaceStorage([a]);
|
||||
const peerB = new SpaceStorage([b]);
|
||||
const peerC = new SpaceStorage([c]);
|
||||
|
||||
peerA.connect();
|
||||
peerB.connect();
|
||||
peerC.connect();
|
||||
|
||||
await peerA.waitForConnected();
|
||||
await peerB.waitForConnected();
|
||||
await peerC.waitForConnected();
|
||||
|
||||
await a.set({
|
||||
key: 'test',
|
||||
data: new Uint8Array([1, 2, 3, 4]),
|
||||
@@ -135,14 +151,6 @@ test('blob', async () => {
|
||||
createdAt: new Date(100),
|
||||
});
|
||||
|
||||
const peerA = new SpaceStorage([a]);
|
||||
const peerB = new SpaceStorage([b]);
|
||||
const peerC = new SpaceStorage([c]);
|
||||
|
||||
await peerA.connect();
|
||||
await peerB.connect();
|
||||
await peerC.connect();
|
||||
|
||||
const sync = new Sync(peerA, [peerB, peerC]);
|
||||
sync.start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user