Migrate to private class properties/methods

This commit is contained in:
Jamie Kyle
2025-01-14 11:11:52 -08:00
committed by GitHub
parent 7dbe57084b
commit aa9f53df57
100 changed files with 3795 additions and 3944 deletions

View File

@@ -20,15 +20,13 @@
import { drop } from './drop';
export class LatestQueue {
private isRunning: boolean;
private queuedTask?: () => Promise<void>;
private onceEmptyCallbacks: Array<() => unknown>;
#isRunning: boolean;
#queuedTask?: () => Promise<void>;
#onceEmptyCallbacks: Array<() => unknown>;
constructor() {
this.isRunning = false;
this.onceEmptyCallbacks = [];
this.#isRunning = false;
this.#onceEmptyCallbacks = [];
}
/**
@@ -39,25 +37,25 @@ export class LatestQueue {
* tasks will be enqueued at a time.
*/
add(task: () => Promise<void>): void {
if (this.isRunning) {
this.queuedTask = task;
if (this.#isRunning) {
this.#queuedTask = task;
} else {
this.isRunning = true;
this.#isRunning = true;
drop(
task().finally(() => {
this.isRunning = false;
this.#isRunning = false;
const { queuedTask } = this;
const queuedTask = this.#queuedTask;
if (queuedTask) {
this.queuedTask = undefined;
this.#queuedTask = undefined;
this.add(queuedTask);
} else {
try {
this.onceEmptyCallbacks.forEach(callback => {
this.#onceEmptyCallbacks.forEach(callback => {
callback();
});
} finally {
this.onceEmptyCallbacks = [];
this.#onceEmptyCallbacks = [];
}
}
})
@@ -69,6 +67,6 @@ export class LatestQueue {
* Adds a callback to be called the first time the queue goes from "running" to "empty".
*/
onceEmpty(callback: () => unknown): void {
this.onceEmptyCallbacks.push(callback);
this.#onceEmptyCallbacks.push(callback);
}
}