-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
Rework some disposing #2128
Rework some disposing #2128
Conversation
} | ||
catch | ||
{ | ||
await browser.DisposeAsync().ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if initAction
or AttachAsync
throws an exception, we now explicitly dispose browser
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
@@ -171,8 +171,14 @@ internal class WaitTask : IDisposable | |||
|
|||
public void Dispose() | |||
{ | |||
Dispose(true); | |||
GC.SuppressFinalize(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the class is now sealed
and there is not finalizer, there's no longer a need for GC.SuppressFinalize(this)
.
public Task DeleteAsync(CancellationToken cancellationToken = default) | ||
=> _deleteTask ?? (_deleteTask = DeleteAsync(Path, CancellationToken.None)); | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_deleteTask == null) | ||
{ | ||
_ = DeleteAsync(); | ||
} | ||
} | ||
|
||
private static async Task DeleteAsync(string path, CancellationToken cancellationToken = default) | ||
private static async Task DeleteAsync(string path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeleteAsync(CancellationToken cancellationToken = default)
has never been used outside this class since it was introduced in #585, so cancellationToken
is always CancellationToken.None
.
I don't have the full overview of what #585 does, so I refrained from removing the fire-and-forget invocation of of DeleteAsync
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job going through this!
} | ||
catch | ||
{ | ||
await browser.DisposeAsync().ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
Found some more places related to disposing to rework.
I've split the changes into three separate commits to ease reviewing.