Reuse global locks, handle empty envelopes

This commit is contained in:
Fedor Indutny 2021-05-19 11:33:14 -07:00 committed by Scott Nonnenberg
parent 25f271e61c
commit 1f0119a7ac
5 changed files with 29 additions and 11 deletions

View file

@ -44,20 +44,22 @@ export type SessionsOptions = {
};
export class Sessions extends SessionStore {
private readonly lock: Lock;
private readonly lock: Lock | undefined;
private inTransaction = false;
constructor(private readonly options: SessionsOptions = {}) {
super();
this.lock = options.lock || new Lock();
this.lock = options.lock;
}
public async transaction<T>(fn: () => Promise<T>): Promise<T> {
assert(!this.inTransaction, 'Already in transaction');
this.inTransaction = true;
assert(this.lock, "Can't start transaction without lock");
try {
return await window.textsecure.storage.protocol.sessionTransaction(
'Sessions.transaction',
@ -117,9 +119,9 @@ export type IdentityKeysOptions = {
};
export class IdentityKeys extends IdentityKeyStore {
private readonly lock: Lock;
private readonly lock: Lock | undefined;
constructor({ lock = new Lock() }: IdentityKeysOptions = {}) {
constructor({ lock }: IdentityKeysOptions = {}) {
super();
this.lock = lock;
}