mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
feat(nbstore): add doc sync frontend (#9070)
This commit is contained in:
@@ -4,6 +4,8 @@ import type { BlobStorage } from '../../storage';
|
||||
import { MANUALLY_STOP, throwIfAborted } from '../../utils/throw-if-aborted';
|
||||
|
||||
export class BlobSyncEngine {
|
||||
private abort: AbortController | null = null;
|
||||
|
||||
constructor(
|
||||
readonly local: BlobStorage,
|
||||
readonly remotes: BlobStorage[]
|
||||
@@ -72,18 +74,24 @@ export class BlobSyncEngine {
|
||||
}
|
||||
}
|
||||
|
||||
async run(signal?: AbortSignal) {
|
||||
if (signal?.aborted) {
|
||||
return;
|
||||
start() {
|
||||
if (this.abort) {
|
||||
this.abort.abort();
|
||||
}
|
||||
|
||||
try {
|
||||
await this.sync(signal);
|
||||
} catch (error) {
|
||||
const abort = new AbortController();
|
||||
this.abort = abort;
|
||||
|
||||
this.sync(abort.signal).catch(error => {
|
||||
if (error === MANUALLY_STOP) {
|
||||
return;
|
||||
}
|
||||
console.error('sync blob error', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.abort?.abort();
|
||||
this.abort = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user