Skip to content

Commit

Permalink
onExtensionStart - Add removeListener
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Mar 16, 2024
1 parent 9948542 commit 34d13a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/on-extension-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,21 @@ describe('onExtensionStart', () => {
expect(listenerSpy).toHaveBeenCalledTimes(0);
expect(listenerSpy2).toHaveBeenCalledTimes(0);
});

it('should not run the listeners if they are removed', async () => {
const {onExtensionStart} = await import('./on-extension-start.js');

const listenerSpy = vi.fn();
const listenerSpy2 = vi.fn();

onExtensionStart.addListener(listenerSpy);
onExtensionStart.addListener(listenerSpy2);

onExtensionStart.removeListener(listenerSpy);

await sleep(100);

expect(listenerSpy).toHaveBeenCalledTimes(0);
expect(listenerSpy2).toHaveBeenCalledTimes(1);
});
});
3 changes: 3 additions & 0 deletions source/on-extension-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const onExtensionStart = Object.freeze({
event.addEventListener('extension-start', callback);
}
},
removeListener(callback: VoidCallback) {
event.removeEventListener('extension-start', callback);
}

Check failure on line 55 in source/on-extension-start.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing trailing comma.

Check failure on line 55 in source/on-extension-start.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing trailing comma.
});

// Automatically register the runner
Expand Down

0 comments on commit 34d13a7

Please sign in to comment.