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

Remove SpinWait #132

Merged
merged 1 commit into from
Nov 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions Mono.Addins.Setup/Mono.Addins.Setup/AddinStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ internal string DownloadFile (IProgressMonitor monitor, string url)
try {
monitor.BeginTask ("Requesting " + url, 2);
var task = DownloadFileRequest.DownloadFile (url, noCache: true);
if (!WaitForTask (task, monitor))
throw new InstallException ("Installation cancelled.");
task.Wait ();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the cancellation token overload.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, bummer, mono-addins monitor does not use cancellation token.

Copy link
Contributor

Choose a reason for hiding this comment

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


using (var request = task.Result) {
monitor.Step (1);
Expand Down Expand Up @@ -679,19 +678,6 @@ internal string DownloadFile (IProgressMonitor monitor, string url)
}
}

static bool WaitForTask (Task<DownloadFileRequest> task, IProgressMonitor monitor)
{
bool result = SpinWait.SpinUntil (() => {
return monitor.IsCancelRequested || task.IsCompleted || task.IsFaulted;
}, 100000); // Use same default timeout as HttpClient.

if (monitor.IsCancelRequested)
return false;
if (!result)
throw new InstallException ("Timed out.");
return result;
}

internal bool HasWriteAccess (string file)
{
FileInfo f = new FileInfo (file);
Expand Down