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

Improve Task usage #1172

Merged
merged 5 commits into from Feb 7, 2020
Merged

Improve Task usage #1172

merged 5 commits into from Feb 7, 2020

Conversation

rjmholt
Copy link
Collaborator

@rjmholt rjmholt commented Jan 30, 2020

Makes the following changes:

  • Changes Task.Factory.StartNew invocations to Task.Run to simplify the child attach semantics (invoking tasks won't hang around for new threads to finish now, since in the places where we use it, it seems we really wanted to kick off a new thread)
  • Removes async/await from methods that just do some setup and run another task
  • Adds a TaskOptions.LongRunning hint to the logger thread so that it's less likely to impact the thread pool. The other option here is to use a new Thread and bypass the thread pool altogether. Happy to do either (but this one represents a smaller change).

@@ -639,267 +639,262 @@ public Task<RunspaceHandle> GetRunspaceHandleAsync(CancellationToken cancellatio
errorMessages,
executionOptions)).ConfigureAwait(false);
}
else

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you hide whitespace changes here, you'll see I just got rid of the else. Been wanting to do that for a while.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM just a couple nits

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM

RunWriter,
CancellationToken.None, // Inner method will manage cancellation
TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach,
TaskScheduler.Default);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this never exits, I'd just throw it in a Thread like you mentioned.

…hellContextService.cs

Co-Authored-By: Tyler James Leonhardt <tylerl0706@gmail.com>
@PowerShell PowerShell deleted a comment from SeeminglyScience Feb 6, 2020
@TylerLeonhardt
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 3
           

See the complete overview on Codacy

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM

@rjmholt rjmholt merged commit d055781 into PowerShell:master Feb 7, 2020
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

3 participants