From 1549d8add0874737c80093918e052281822fe785 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 16 Nov 2021 15:26:40 +0530 Subject: [PATCH] Convert LockMap to ts --- src/matrix/Session.js | 2 +- src/utils/{LockMap.js => LockMap.ts} | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) rename src/utils/{LockMap.js => LockMap.ts} (92%) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 37fd90ad..874bfecd 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -34,7 +34,7 @@ import {Encryption as MegOlmEncryption} from "./e2ee/megolm/Encryption.js"; import {MEGOLM_ALGORITHM} from "./e2ee/common.js"; import {RoomEncryption} from "./e2ee/RoomEncryption.js"; import {DeviceTracker} from "./e2ee/DeviceTracker.js"; -import {LockMap} from "../utils/LockMap.js"; +import {LockMap} from "../utils/LockMap"; import {groupBy} from "../utils/groupBy"; import { keyFromCredential as ssssKeyFromCredential, diff --git a/src/utils/LockMap.js b/src/utils/LockMap.ts similarity index 92% rename from src/utils/LockMap.js rename to src/utils/LockMap.ts index 567acf4c..5952f031 100644 --- a/src/utils/LockMap.js +++ b/src/utils/LockMap.ts @@ -17,11 +17,9 @@ limitations under the License. import {Lock} from "./Lock"; export class LockMap { - constructor() { - this._map = new Map(); - } + private readonly _map: Map = new Map(); - async takeLock(key) { + async takeLock(key: unknown): Promise { let lock = this._map.get(key); if (lock) { await lock.take(); @@ -31,10 +29,10 @@ export class LockMap { this._map.set(key, lock); } // don't leave old locks lying around - lock.released().then(() => { + lock.released()!.then(() => { // give others a chance to take the lock first Promise.resolve().then(() => { - if (!lock.isTaken) { + if (!lock!.isTaken) { this._map.delete(key); } }); @@ -67,6 +65,7 @@ export function tests() { ranSecond = true; assert.equal(returnedLock.isTaken, true); // peek into internals, naughty + // @ts-ignore assert.equal(lockMap._map.get("foo"), returnedLock); }); lock.release(); @@ -84,6 +83,7 @@ export function tests() { // double delay to make sure cleanup logic ran await Promise.resolve(); await Promise.resolve(); + // @ts-ignore assert.equal(lockMap._map.has("foo"), false); },