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

Rework some disposing #2128

Merged
merged 3 commits into from
Apr 9, 2023
Merged

Rework some disposing #2128

merged 3 commits into from
Apr 9, 2023

Conversation

jnyrup
Copy link
Contributor

@jnyrup jnyrup commented Apr 8, 2023

Found some more places related to disposing to rework.
I've split the changes into three separate commits to ease reviewing.

}
catch
{
await browser.DisposeAsync().ConfigureAwait(false);
Copy link
Contributor Author

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.

Copy link
Member

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);
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

Copy link
Member

@kblok kblok left a 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);
Copy link
Member

Choose a reason for hiding this comment

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

Good point.

@kblok kblok merged commit fb55c41 into hardkoded:master Apr 9, 2023
@jnyrup jnyrup deleted the Disposing branch April 9, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants