mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Remove identifier parameter
This commit is contained in:
parent
6f4c4a15b4
commit
acebf030c7
@ -1,5 +1,4 @@
|
|||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
|
||||||
import { getLoggerFor } from '../logging/LogUtil';
|
import { getLoggerFor } from '../logging/LogUtil';
|
||||||
import type { ExpiringLock } from './ExpiringLock';
|
import type { ExpiringLock } from './ExpiringLock';
|
||||||
import type { Lock } from './Lock';
|
import type { Lock } from './Lock';
|
||||||
@ -15,19 +14,16 @@ export class WrappedExpiringLock extends EventEmitter implements ExpiringLock {
|
|||||||
|
|
||||||
protected readonly innerLock: Lock;
|
protected readonly innerLock: Lock;
|
||||||
protected readonly expiration: number;
|
protected readonly expiration: number;
|
||||||
protected readonly identifier: ResourceIdentifier;
|
|
||||||
protected timeoutHandle?: NodeJS.Timeout;
|
protected timeoutHandle?: NodeJS.Timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param innerLock - Instance of ResourceLocker to use for acquiring a lock.
|
* @param innerLock - Instance of ResourceLocker to use for acquiring a lock.
|
||||||
* @param expiration - Time in ms after which the lock expires.
|
* @param expiration - Time in ms after which the lock expires.
|
||||||
* @param identifier - Identifier of the resource that needs to be locked.
|
|
||||||
*/
|
*/
|
||||||
public constructor(innerLock: Lock, expiration: number, identifier: ResourceIdentifier) {
|
public constructor(innerLock: Lock, expiration: number) {
|
||||||
super();
|
super();
|
||||||
this.innerLock = innerLock;
|
this.innerLock = innerLock;
|
||||||
this.expiration = expiration;
|
this.expiration = expiration;
|
||||||
this.identifier = identifier;
|
|
||||||
this.scheduleTimeout();
|
this.scheduleTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +45,7 @@ export class WrappedExpiringLock extends EventEmitter implements ExpiringLock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async expire(): Promise<void> {
|
private async expire(): Promise<void> {
|
||||||
this.logger.verbose(`Lock for ${this.identifier.path} expired after ${this.expiration}ms`);
|
this.logger.verbose(`Lock expired after ${this.expiration}ms`);
|
||||||
this.emit('expired');
|
this.emit('expired');
|
||||||
try {
|
try {
|
||||||
await this.innerLock.release();
|
await this.innerLock.release();
|
||||||
@ -63,7 +59,7 @@ export class WrappedExpiringLock extends EventEmitter implements ExpiringLock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private scheduleTimeout(): void {
|
private scheduleTimeout(): void {
|
||||||
this.logger.verbose(`Renewed expiring lock for ${this.identifier.path}`);
|
this.logger.verbose(`Renewed expiring lock`);
|
||||||
this.timeoutHandle = setTimeout((): any => this.expire(), this.expiration);
|
this.timeoutHandle = setTimeout((): any => this.expire(), this.expiration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,6 @@ export class WrappedExpiringResourceLocker implements ExpiringResourceLocker {
|
|||||||
*/
|
*/
|
||||||
public async acquire(identifier: ResourceIdentifier): Promise<ExpiringLock> {
|
public async acquire(identifier: ResourceIdentifier): Promise<ExpiringLock> {
|
||||||
const innerLock = await this.locker.acquire(identifier);
|
const innerLock = await this.locker.acquire(identifier);
|
||||||
return new WrappedExpiringLock(innerLock, this.expiration, identifier);
|
return new WrappedExpiringLock(innerLock, this.expiration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user