Skip to content

Commit

Permalink
fixup! error in dispose listener after emitter disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jun 22, 2023
1 parent 30e2bd1 commit b1756f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/vs/base/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ export class Emitter<T> {
}

this._listeners = undefined;
this._size = 0;
}
this._options?.onDidRemoveLastListener?.();
this._leakageMon?.dispose();
Expand Down
3 changes: 2 additions & 1 deletion src/vs/base/test/common/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ suite('Event', function () {
test('Emitter, dispose emitter during emission', () => {
const emitter = new Emitter<void>();
const calls: number[] = [];
Array.from({ length: 25 }, (_, n) => emitter.event(() => {
const disposables = Array.from({ length: 25 }, (_, n) => emitter.event(() => {
if (n === 10) {
emitter.dispose();
}
calls.push(n);
}));

emitter.fire();
disposables.forEach(d => d.dispose());
assert.deepStrictEqual(calls, Array.from({ length: 11 }, (_, n) => n));
});

Expand Down

0 comments on commit b1756f9

Please sign in to comment.