Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/MatrixClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ export class MatrixClient extends EventEmitter {
return this.startSync();
}

protected emitAsync(e: string, ...p: any[]): Promise<any> {
return Promise.resolve<any>(this.emit(e, ...p));
}

protected async startSync(emitFn: (emitEventType: string, ...payload: any[]) => Promise<any> = null) {
// noinspection ES6RedundantAwait
let token = await Promise.resolve(this.storage.getSyncToken());
Expand Down Expand Up @@ -728,6 +732,8 @@ export class MatrixClient extends EventEmitter {
}

LogService.error("MatrixClientLite", "Error handling sync " + extractRequestError(e));
await this.emitAsync("sync.error", e);

const backoffTime = SYNC_BACKOFF_MIN_MS + Math.random() * (SYNC_BACKOFF_MAX_MS - SYNC_BACKOFF_MIN_MS);
LogService.info("MatrixClientLite", `Backing off for ${backoffTime}ms`);
await new Promise((r) => setTimeout(r, backoffTime));
Expand Down Expand Up @@ -757,7 +763,7 @@ export class MatrixClient extends EventEmitter {

@timedMatrixClientFunctionCall()
protected async processSync(raw: any, emitFn: (emitEventType: string, ...payload: any[]) => Promise<any> = null): Promise<any> {
if (!emitFn) emitFn = (e, ...p) => Promise.resolve<any>(this.emit(e, ...p));
if (!emitFn) emitFn = (e, ...p) => this.emitAsync(e, ...p);

if (!raw) return; // nothing to process

Expand Down