Migrate to private class properties/methods
This commit is contained in:
parent
7dbe57084b
commit
aa9f53df57
100 changed files with 3795 additions and 3944 deletions
|
@ -9,31 +9,31 @@ import { PreventDisplaySleepService } from '../../../app/PreventDisplaySleepServ
|
|||
|
||||
describe('PreventDisplaySleepService', () => {
|
||||
class FakePowerSaveBlocker implements PowerSaveBlocker {
|
||||
private nextId = 0;
|
||||
private idsStarted = new Set<number>();
|
||||
#nextId = 0;
|
||||
#idsStarted = new Set<number>();
|
||||
|
||||
isStarted(id: number): boolean {
|
||||
return this.idsStarted.has(id);
|
||||
return this.#idsStarted.has(id);
|
||||
}
|
||||
|
||||
start(type: 'prevent-app-suspension' | 'prevent-display-sleep'): number {
|
||||
assert.strictEqual(type, 'prevent-display-sleep');
|
||||
|
||||
const result = this.nextId;
|
||||
this.nextId += 1;
|
||||
this.idsStarted.add(result);
|
||||
const result = this.#nextId;
|
||||
this.#nextId += 1;
|
||||
this.#idsStarted.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
stop(id: number): boolean {
|
||||
assert(this.idsStarted.has(id), `${id} was never started`);
|
||||
this.idsStarted.delete(id);
|
||||
assert(this.#idsStarted.has(id), `${id} was never started`);
|
||||
this.#idsStarted.delete(id);
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is only for testing.
|
||||
_idCount(): number {
|
||||
return this.idsStarted.size;
|
||||
return this.#idsStarted.size;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -733,18 +733,18 @@ describe('JobQueue', () => {
|
|||
});
|
||||
|
||||
class FakeStream implements AsyncIterable<StoredJob> {
|
||||
private eventEmitter = new EventEmitter();
|
||||
#eventEmitter = new EventEmitter();
|
||||
|
||||
async *[Symbol.asyncIterator]() {
|
||||
while (true) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const [job] = await once(this.eventEmitter, 'drip');
|
||||
const [job] = await once(this.#eventEmitter, 'drip');
|
||||
yield parseUnknown(storedJobSchema, job as unknown);
|
||||
}
|
||||
}
|
||||
|
||||
drip(job: Readonly<StoredJob>): void {
|
||||
this.eventEmitter.emit('drip', job);
|
||||
this.#eventEmitter.emit('drip', job);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,8 @@ import { drop } from '../../util/drop';
|
|||
export class TestJobQueueStore implements JobQueueStore {
|
||||
events = new EventEmitter();
|
||||
|
||||
private openStreams = new Set<string>();
|
||||
|
||||
private pipes = new Map<string, Pipe>();
|
||||
#openStreams = new Set<string>();
|
||||
#pipes = new Map<string, Pipe>();
|
||||
|
||||
storedJobs: Array<StoredJob> = [];
|
||||
|
||||
|
@ -41,7 +40,7 @@ export class TestJobQueueStore implements JobQueueStore {
|
|||
this.storedJobs.push(job);
|
||||
}
|
||||
|
||||
this.getPipe(job.queueType).add(job);
|
||||
this.#getPipe(job.queueType).add(job);
|
||||
|
||||
this.events.emit('insert');
|
||||
}
|
||||
|
@ -55,78 +54,75 @@ export class TestJobQueueStore implements JobQueueStore {
|
|||
}
|
||||
|
||||
stream(queueType: string): Pipe {
|
||||
if (this.openStreams.has(queueType)) {
|
||||
if (this.#openStreams.has(queueType)) {
|
||||
throw new Error('Cannot stream the same queueType more than once');
|
||||
}
|
||||
this.openStreams.add(queueType);
|
||||
this.#openStreams.add(queueType);
|
||||
|
||||
return this.getPipe(queueType);
|
||||
return this.#getPipe(queueType);
|
||||
}
|
||||
|
||||
pauseStream(queueType: string): void {
|
||||
return this.getPipe(queueType).pause();
|
||||
return this.#getPipe(queueType).pause();
|
||||
}
|
||||
|
||||
resumeStream(queueType: string): void {
|
||||
return this.getPipe(queueType).resume();
|
||||
return this.#getPipe(queueType).resume();
|
||||
}
|
||||
|
||||
private getPipe(queueType: string): Pipe {
|
||||
const existingPipe = this.pipes.get(queueType);
|
||||
#getPipe(queueType: string): Pipe {
|
||||
const existingPipe = this.#pipes.get(queueType);
|
||||
if (existingPipe) {
|
||||
return existingPipe;
|
||||
}
|
||||
|
||||
const result = new Pipe();
|
||||
this.pipes.set(queueType, result);
|
||||
this.#pipes.set(queueType, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class Pipe implements AsyncIterable<StoredJob> {
|
||||
private queue: Array<StoredJob> = [];
|
||||
|
||||
private eventEmitter = new EventEmitter();
|
||||
|
||||
private isLocked = false;
|
||||
|
||||
private isPaused = false;
|
||||
#queue: Array<StoredJob> = [];
|
||||
#eventEmitter = new EventEmitter();
|
||||
#isLocked = false;
|
||||
#isPaused = false;
|
||||
|
||||
add(value: Readonly<StoredJob>) {
|
||||
this.queue.push(value);
|
||||
this.eventEmitter.emit('add');
|
||||
this.#queue.push(value);
|
||||
this.#eventEmitter.emit('add');
|
||||
}
|
||||
|
||||
async *[Symbol.asyncIterator]() {
|
||||
if (this.isLocked) {
|
||||
if (this.#isLocked) {
|
||||
throw new Error('Cannot iterate over a pipe more than once');
|
||||
}
|
||||
this.isLocked = true;
|
||||
this.#isLocked = true;
|
||||
|
||||
while (true) {
|
||||
for (const value of this.queue) {
|
||||
await this.waitForUnpaused();
|
||||
for (const value of this.#queue) {
|
||||
await this.#waitForUnpaused();
|
||||
yield value;
|
||||
}
|
||||
this.queue = [];
|
||||
this.#queue = [];
|
||||
|
||||
// We do this because we want to yield values in series.
|
||||
await once(this.eventEmitter, 'add');
|
||||
await once(this.#eventEmitter, 'add');
|
||||
}
|
||||
}
|
||||
|
||||
pause(): void {
|
||||
this.isPaused = true;
|
||||
this.#isPaused = true;
|
||||
}
|
||||
|
||||
resume(): void {
|
||||
this.isPaused = false;
|
||||
this.eventEmitter.emit('resume');
|
||||
this.#isPaused = false;
|
||||
this.#eventEmitter.emit('resume');
|
||||
}
|
||||
|
||||
private async waitForUnpaused() {
|
||||
if (this.isPaused) {
|
||||
await once(this.eventEmitter, 'resume');
|
||||
async #waitForUnpaused() {
|
||||
if (this.#isPaused) {
|
||||
await once(this.#eventEmitter, 'resume');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue