Skip to content

Commit

Permalink
Avoiding System.Threading.Tasks.TaskCanceledException : A task was ca…
Browse files Browse the repository at this point in the history
…nceled.
  • Loading branch information
John Simons committed Feb 23, 2016
1 parent bcf4443 commit 4afc98d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/ServiceControl.AcceptanceTesting/Support/EndpointRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ public Result Initialize(RunDescriptor run, EndpointBehavior endpointBehavior,
}

//we spin around each 5s since the callback mechanism seems to be shaky
await contextChanged.WaitAsync(TimeSpan.FromSeconds(5), stopToken);

if (stopToken.IsCancellationRequested)
try
{
await contextChanged.WaitAsync(TimeSpan.FromSeconds(5), stopToken);
}
catch (OperationCanceledException)
{
break;
}

foreach (var when in behavior.Whens)
{
if (stopToken.IsCancellationRequested)
{
return;
}

if (executedWhens.Contains(when.Id))
{
continue;
Expand All @@ -104,7 +110,7 @@ public Result Initialize(RunDescriptor run, EndpointBehavior endpointBehavior,
}
}
}
}, stopToken).Unwrap();
}).Unwrap();
}
return Result.Success();
}
Expand Down

0 comments on commit 4afc98d

Please sign in to comment.