fix: reset mutex on closing a site app window, freeing the lock
This commit is contained in:
parent
4e15730858
commit
9a7bd1d688
|
@ -59,6 +59,7 @@ export abstract class AppWindow implements IAppWindow {
|
|||
this.sessionHelper.setCsp(this._window, this.getCsp());
|
||||
|
||||
this._window.on('closed', () => {
|
||||
this.onClosed();
|
||||
this._window = null;
|
||||
});
|
||||
|
||||
|
@ -97,5 +98,7 @@ export abstract class AppWindow implements IAppWindow {
|
|||
event.preventDefault();
|
||||
}
|
||||
|
||||
protected onClosed(): void {}
|
||||
|
||||
protected abstract load(window: BrowserWindow): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -24,4 +24,8 @@ export abstract class SiteAppWindow extends UrlAppWindow implements ISiteAppWind
|
|||
public acquireLock(): Promise<Mutex.ReleaseFunction> {
|
||||
return this.windowLock.acquire();
|
||||
}
|
||||
|
||||
protected onClosed(): void {
|
||||
this.windowLock.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,16 @@ interface IMutex {
|
|||
*/
|
||||
acquire(): Promise<Mutex.ReleaseFunction>;
|
||||
|
||||
/**
|
||||
* release the lock and execute the next consumer.
|
||||
*/
|
||||
release(): void;
|
||||
|
||||
/**
|
||||
* release the lock and do not allow any current consumers to execute.
|
||||
*/
|
||||
reset(): void;
|
||||
|
||||
isLocked(): boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,16 @@ export class SimpleMutex implements IMutex {
|
|||
});
|
||||
}
|
||||
|
||||
public release(): void {
|
||||
this.locked = false;
|
||||
this.dispatch();
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this.queue = [];
|
||||
this.locked = false;
|
||||
}
|
||||
|
||||
public isLocked(): boolean {
|
||||
return this.locked;
|
||||
}
|
||||
|
@ -37,13 +47,13 @@ export class SimpleMutex implements IMutex {
|
|||
if (!nextResolve) {
|
||||
return;
|
||||
}
|
||||
// lock the resource
|
||||
this.locked = true;
|
||||
|
||||
// this is the function which gets called by the consumer to release the lock
|
||||
// it also dispatches the next consumer
|
||||
const releaseFunction = (): void => {
|
||||
this.locked = false;
|
||||
this.dispatch();
|
||||
this.release();
|
||||
};
|
||||
|
||||
// lock the resource and resolve the promise so the consumer can do its thing
|
||||
|
|
Loading…
Reference in New Issue