Convert LockMap to ts
This commit is contained in:
parent
c8eb7ea7ac
commit
1549d8add0
2 changed files with 7 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -17,11 +17,9 @@ limitations under the License.
|
|||
import {Lock} from "./Lock";
|
||||
|
||||
export class LockMap {
|
||||
constructor() {
|
||||
this._map = new Map();
|
||||
}
|
||||
private readonly _map: Map<unknown, Lock> = new Map();
|
||||
|
||||
async takeLock(key) {
|
||||
async takeLock(key: unknown): Promise<Lock> {
|
||||
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);
|
||||
},
|
||||
|
Reference in a new issue