Skip to content

Commit

Permalink
Resources: support TaskCanceledException handling for different .NET …
Browse files Browse the repository at this point in the history
…environment (#1019)

* Resources: add exception handling when task is canceled

* Resources: fix else if

* Resources: handle request cancellation
  • Loading branch information
xseeseesee authored Apr 9, 2020
1 parent 8b3b95e commit 7e3dc5b
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ public Task<List<FluentModelTImpl>> CommitAndGetAllAsync(CancellationToken cance
exceptions.Add(deleteTask.Exception);
}
}
else if (deleteTask.IsCanceled)
{
cancellationToken.ThrowIfCancellationRequested();
exceptions.Add(new TaskCanceledException());
}
else
{
comitted.Add(res);
res.PendingOperation = PendingOperation.None;
FluentModelTImpl val;
this.collection.TryRemove(res.Name(), out val);
this.collection.TryRemove(res.Name(), out FluentModelTImpl val);
}
},
cancellationToken,
Expand All @@ -91,8 +95,7 @@ public Task<List<FluentModelTImpl>> CommitAndGetAllAsync(CancellationToken cance
{
if (createTask.IsFaulted)
{
FluentModelTImpl val;
this.collection.TryRemove(res.Name(), out val);
this.collection.TryRemove(res.Name(), out FluentModelTImpl val);
if (createTask.Exception.InnerException != null)
{
exceptions.Add(createTask.Exception.InnerException);
Expand All @@ -102,6 +105,12 @@ public Task<List<FluentModelTImpl>> CommitAndGetAllAsync(CancellationToken cance
exceptions.Add(createTask.Exception);
}
}
else if (createTask.IsCanceled)
{
this.collection.TryRemove(res.Name(), out FluentModelTImpl val);
cancellationToken.ThrowIfCancellationRequested();
exceptions.Add(new TaskCanceledException());
}
else
{
comitted.Add(res);
Expand Down Expand Up @@ -131,6 +140,11 @@ public Task<List<FluentModelTImpl>> CommitAndGetAllAsync(CancellationToken cance
exceptions.Add(updateTask.Exception);
}
}
else if (updateTask.IsCanceled)
{
cancellationToken.ThrowIfCancellationRequested();
exceptions.Add(new TaskCanceledException());
}
else
{
comitted.Add(res);
Expand Down

0 comments on commit 7e3dc5b

Please sign in to comment.