From 2596999cb878ae2eba644eaa55b41a12aed66e17 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 8 Aug 2022 14:26:24 +0100 Subject: [PATCH] Review comments --- src/sliding-sync.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/sliding-sync.ts b/src/sliding-sync.ts index 9ce62a073..9d5cefe02 100644 --- a/src/sliding-sync.ts +++ b/src/sliding-sync.ts @@ -19,7 +19,7 @@ import { IAbortablePromise } from "./@types/partials"; import { MatrixClient } from "./client"; import { IRoomEvent, IStateEvent } from "./sync-accumulator"; import { TypedEventEmitter } from "./models//typed-event-emitter"; -import { sleep } from "./utils"; +import { sleep, IDeferred, defer } from "./utils"; // /sync requests allow you to set a timeout= but the request may continue // beyond that and wedge forever, so we need to track how long we are willing @@ -340,7 +340,7 @@ export class SlidingSync extends TypedEventEmitter & { txnId: string})[] = []; // map of extension name to req/resp handler private extensions: Record = {}; @@ -410,6 +410,9 @@ export class SlidingSync extends TypedEventEmitter { this.lists[index].updateListRange(ranges); @@ -421,6 +424,9 @@ export class SlidingSync extends TypedEventEmitter { if (this.lists[index]) { @@ -445,6 +451,9 @@ export class SlidingSync extends TypedEventEmitter): Promise { this.desiredRoomSubscriptions = s; @@ -455,6 +464,9 @@ export class SlidingSync extends TypedEventEmitter { this.roomSubscriptionInfo = rs; @@ -628,16 +640,14 @@ export class SlidingSync extends TypedEventEmitter { this.needsResend = true; - this.txnId = ""+Math.random(); - const p: Promise = new Promise((resolve, reject) => { - this.txnIdDefers.push({ - txnId: this.txnId, - resolve: resolve, - reject: reject, - }); + this.txnId = this.client.makeTxnId(); + const d = defer(); + this.txnIdDefers.push({ + ...d, + txnId: this.txnId, }); this.pendingReq?.abort(); - return p; + return d.promise; } private resolveTransactionDefers(txnId?: string) {