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

Replace JTF.RunAsync() with exception-safe wrappers #11152

Merged
merged 2 commits into from Sep 18, 2023

Conversation

mstv
Copy link
Member

@mstv mstv commented Aug 14, 2023

Follow-up to #11136 (and #11137 (comment))
inspired by d5b8f33

Proposed changes

  • Replace JoinableTaskFactory.RunAsync() with exception-safe wrappers FileAndForget or InvokeAndForget, respectively
  • Replace and remove GitUIExtensions.InvokeSync() and GitUIExtensions.InvokeAsync()

Screenshots

N/A

Test methodology

  • exisiting tests

Please do not squash merge ❗


✒️ I contribute this code under The Developer Certificate of Origin.

@mstv mstv self-assigned this Aug 14, 2023
}).FileAndForget();

return;
SelectedDiff.InvokeAndForget(() => SelectedDiff.ViewChangesAsync(item, openWithDiffTool: OpenWithDiffTool, cancellationToken: _viewChangesSequence.Next()));
Copy link
Member

Choose a reason for hiding this comment

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

The issue with this change it makes it close to impossible to mock the threading context. The current implementation allows us to replace the static ThreadHelper reference with an injected instance that provides JTF, but in the new implementation we won't be able to do that...

Copy link
Member Author

Choose a reason for hiding this comment

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

The injection of a JTF instance should be no big deal: The class TaskManager provides / encapsulates the JTF instance.
With the initial implementation, it would look like:

_taskManager.InvokeAndForget(SelectedDiff, () => SelectedDiff.ViewChangesAsync(...));

With another argument added to the extension method, it can be written as before (preferred):

SelectedDiff.InvokeAndForget(() => SelectedDiff.ViewChangesAsync(...), _taskManager);

Furthermore, I should feed every already available CancellationToken to InvokeAndForget(), too - but in another follow-up PR:

CancellationToken cancellationToken = _viewChangesSequence.Next();
SelectedDiff.InvokeAndForget(() => SelectedDiff.ViewChangesAsync(..., cancellationToken), _taskManager, cancellationToken);

@mstv
Copy link
Member Author

mstv commented Aug 17, 2023

On hold: The test execution will improve / work again after merging the 3 today's PRs.

@mstv
Copy link
Member Author

mstv commented Aug 30, 2023

needs #11162

@mstv mstv merged commit 224359c into gitextensions:master Sep 18, 2023
3 of 4 checks passed
@ghost ghost added this to the vNext milestone Sep 18, 2023
@mstv mstv deleted the fix/jtf_runasync branch September 18, 2023 17:20
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.

None yet

2 participants