Skip to content

Commit 6d4576a

Browse files
committed
style(lockfile): add more commentation
1 parent e6a2237 commit 6d4576a

File tree

1 file changed

+12
-3
lines changed
  • packages/mongodb-memory-server-core/src/util

1 file changed

+12
-3
lines changed

packages/mongodb-memory-server-core/src/util/lockfile.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class LockFile {
3434
static files: Set<string> = new Set();
3535
/** Listen for events from this process */
3636
static events: LockFileEventsClass = new LockFileEventsClass();
37+
/** Mutex to stop same-process race conditions */
3738
static mutex: Mutex = new Mutex();
3839

3940
/**
@@ -89,7 +90,9 @@ export class LockFile {
8990
*/
9091
protected static async waitForLock(file: string): Promise<LockFile> {
9192
log(`waitForLock: Starting to wait for file "${file}"`);
93+
/** Store the interval id to be cleared later */
9294
let interval: NodeJS.Timeout | undefined = undefined;
95+
/** Store the function in an value to be cleared later, without having to use an class-external or class function */
9396
let eventCB: ((val: any) => any) | undefined = undefined;
9497
await new Promise<void>((res) => {
9598
eventCB = (unlockedFile) => {
@@ -161,14 +164,20 @@ export class LockFile {
161164
return new this(file);
162165
}
163166

164-
/** File locked by this instance */
167+
// Below here are instance functions & values
168+
169+
/**
170+
* File locked by this instance
171+
*/
165172
public file?: string;
166173

167174
constructor(file: string) {
168175
this.file = file;
169176
}
170177

171-
/** Unlock the File that is locked by this instance */
178+
/**
179+
* Unlock the File that is locked by this instance
180+
*/
172181
async unlock(): Promise<void> {
173182
await utils.ensureAsync();
174183
log(`unlock: Unlocking file "${this.file}"`);
@@ -214,7 +223,7 @@ export class LockFile {
214223
LockFile.files.delete(this.file);
215224
LockFile.events.emit(LockFileEvents.unlock, this.file);
216225

217-
// making this instance unusable (to prevent double calling)
226+
// make this LockFile instance unusable (to prevent double unlock calling)
218227
this.file = undefined;
219228

220229
await utils.ensureAsync();

0 commit comments

Comments
 (0)