Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix onBell listener being registered after term dispose, allow for DisposableStore-managed disposableTimeouts #193583

Merged
merged 7 commits into from
Sep 20, 2023

Conversation

Tyriar
Copy link
Member

@Tyriar Tyriar commented Sep 20, 2023

Fixes #190251

@Tyriar Tyriar added this to the September 2023 milestone Sep 20, 2023
@Tyriar Tyriar self-assigned this Sep 20, 2023
@Tyriar Tyriar changed the title Fix onBell listener being registered after term dispose Fix onBell listener being registered after term dispose, allow for DisposableStore-managed disposableTimeouts Sep 20, 2023
@Tyriar Tyriar marked this pull request as ready for review September 20, 2023 16:59
@Tyriar Tyriar merged commit afd55f2 into main Sep 20, 2023
6 checks passed
@Tyriar Tyriar deleted the tyriar/190251 branch September 20, 2023 19:59
return;
}
if ((o as unknown as DisposableStore) === this) {
throw new Error('Cannot dispose a disposable on itself!');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this happen in practice? If so, I think the error message should be adjusted and BugIndicatingError should be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 just doing what add does

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least the error message is weird.

* disposable even when the disposable is not part in the store.
*/
public delete<T extends IDisposable>(o: T): void {
if (!o) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checks should prevent this from ever happening:

Code_-_Insiders_2h0lrwsH89

I would either change it to o: T | undefined or remove that check (otherwise it might swallow fishy runtime behavior).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It aligns with Set.delete, the if (!o) check if to make it work the same as DisposableStore.add

* Deletes a disposable from store and disposes of it. This will not throw or warn and proceed to dispose the
* disposable even when the disposable is not part in the store.
*/
public delete<T extends IDisposable>(o: T): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is called Set.delete, but I think this method should be called remove. Better even would be removeAndDispose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to call it remove, but it's using add and delete internally on Set which aligns with the web api. Instead of delete and deleteAndDispose, I flipped them do delete (and dispose, common case) and deleteAndLeak (rare case).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just think it might be surprising that delete also disposes the object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think the opposite, the main concern is leaks so disposing is the safe option imo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can be explicit on both though, as long as the leak one is called out

@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to add a disposable to a DisposableStore that has already been disposed of
3 participants