Skip to content

Commit efc0f61

Browse files
committed
improve interface by making bad state impossible
1 parent f192573 commit efc0f61

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

packages/core/src/awsService/apprunner/explorer/apprunnerNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class AppRunnerNode extends AWSTreeNodeBase {
9393
}
9494

9595
public startPollingNode(id: string): void {
96-
this.pollingSet.start(id)
96+
this.pollingSet.add(id)
9797
}
9898

9999
public stopPollingNode(id: string): void {

packages/core/src/awsService/ec2/explorer/ec2ParentNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Ec2ParentNode extends AWSTreeNodeBase {
4545
if (!this.ec2InstanceNodes.has(instanceId)) {
4646
throw new Error(`Attempt to track ec2 node ${instanceId} that isn't a child`)
4747
}
48-
this.pollingSet.start(instanceId)
48+
this.pollingSet.add(instanceId)
4949
}
5050

5151
public async updateChildren(): Promise<void> {

packages/core/src/shared/utilities/pollingSet.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ export class PollingSet<T> extends Set<T> {
4444
this.clearTimer()
4545
}
4646
}
47-
// TODO(hkobew): Overwrite the add method instead of adding seperate method. If we add item to set, timer should always start.
48-
public start(id: T): void {
49-
this.add(id)
47+
48+
public override add(id: T) {
49+
super.add(id)
5050
this.pollTimer = this.pollTimer ?? globals.clock.setInterval(() => this.poll(), this.interval)
51+
return this
5152
}
5253

5354
public override clear(): void {

packages/core/src/shared/utilities/processUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class ChildProcessTracker {
119119
public add(childProcess: ChildProcess) {
120120
const pid = childProcess.pid()
121121
this.#processByPid.set(pid, childProcess)
122-
this.#pids.start(pid)
122+
this.#pids.add(pid)
123123
}
124124

125125
public delete(childProcessId: number) {

packages/core/src/test/shared/utilities/pollingSet.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('pollingSet', function () {
5656
const action = sinon.spy()
5757
pollingSet = new PollingSet(10, action)
5858
sinon.assert.notCalled(action)
59-
pollingSet.start('item')
59+
pollingSet.add('item')
6060

6161
await clock.tickAsync(9)
6262
sinon.assert.notCalled(action)
@@ -66,7 +66,7 @@ describe('pollingSet', function () {
6666

6767
it('stops timer once polling set is empty', async function () {
6868
const pollingSet = new PollingSet(10, () => {})
69-
pollingSet.start('1')
69+
pollingSet.add('1')
7070
pollingSet.add('2')
7171

7272
const clearStub = sinon.stub(pollingSet, 'clearTimer')
@@ -90,7 +90,7 @@ describe('pollingSet', function () {
9090
it('runs action once per interval', async function () {
9191
const action = sinon.spy()
9292
pollingSet = new PollingSet(10, action)
93-
pollingSet.start('1')
93+
pollingSet.add('1')
9494
pollingSet.add('2')
9595

9696
sinon.assert.callCount(action, 0)

0 commit comments

Comments
 (0)