fix(nbstore): connect before do operation (#11569)

This commit is contained in:
EYHN
2025-04-10 16:05:46 +08:00
committed by GitHub
parent 3629a725d2
commit a759a1988e
9 changed files with 150 additions and 104 deletions

View File

@@ -172,28 +172,14 @@ class WorkerDocConnection extends DummyConnection {
super();
}
override waitForConnected(signal?: AbortSignal): Promise<void> {
return new Promise((resolve, reject) => {
const abortListener = () => {
reject(signal?.reason);
subscription.unsubscribe();
};
promise: Promise<void> | undefined;
signal?.addEventListener('abort', abortListener);
const subscription = this.client
.ob$('docStorage.waitForConnected')
.subscribe({
next() {
signal?.removeEventListener('abort', abortListener);
resolve();
},
error(err) {
signal?.removeEventListener('abort', abortListener);
reject(err);
},
});
});
override waitForConnected(): Promise<void> {
if (this.promise) {
return this.promise;
}
this.promise = this.client.call('docStorage.waitForConnected');
return this.promise;
}
}
@@ -226,7 +212,23 @@ class WorkerBlobStorage implements BlobStorage {
return this.client.call('blobStorage.listBlobs');
}
connection = new DummyConnection();
connection = new WorkerBlobConnection(this.client);
}
class WorkerBlobConnection extends DummyConnection {
constructor(private readonly client: OpClient<WorkerOps>) {
super();
}
promise: Promise<void> | undefined;
override waitForConnected(): Promise<void> {
if (this.promise) {
return this.promise;
}
this.promise = this.client.call('blobStorage.waitForConnected');
return this.promise;
}
}
class WorkerDocSync implements DocSync {
@@ -346,7 +348,7 @@ class WorkerIndexerStorage implements IndexerStorage {
constructor(private readonly client: OpClient<WorkerOps>) {}
readonly storageType = 'indexer';
readonly isReadonly = true;
connection = new DummyConnection();
connection = new WorkerIndexerConnection(this.client);
search<T extends keyof IndexerSchema, const O extends SearchOptions<T>>(
table: T,
@@ -421,6 +423,22 @@ class WorkerIndexerStorage implements IndexerStorage {
}
}
class WorkerIndexerConnection extends DummyConnection {
constructor(private readonly client: OpClient<WorkerOps>) {
super();
}
promise: Promise<void> | undefined;
override waitForConnected(): Promise<void> {
if (this.promise) {
return this.promise;
}
this.promise = this.client.call('indexerStorage.waitForConnected');
return this.promise;
}
}
class WorkerIndexerSync implements IndexerSync {
constructor(private readonly client: OpClient<WorkerOps>) {}
waitForCompleted(signal?: AbortSignal): Promise<void> {