Skip to content

Commit dfe3fe0

Browse files
committed
code_style: command cancellation
Signed-off-by: leo <longshuang@msn.cn>
1 parent 4257e0f commit dfe3fe0

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/App.Extensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Text;
5+
using System.Threading;
56
using Avalonia.Media;
67

78
namespace SourceGit
@@ -79,6 +80,12 @@ public static T Use<T>(this T cmd, Models.ICommandLog log) where T : Commands.Co
7980
cmd.Log = log;
8081
return cmd;
8182
}
83+
84+
public static T WithCancellation<T>(this T cmd, CancellationToken token) where T : Commands.Command
85+
{
86+
cmd.CancellationToken = token;
87+
return cmd;
88+
}
8289
}
8390

8491
public static class DirectoryInfoExtension

src/Commands/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task<bool> ExecAsync()
6262
lock (capturedLock)
6363
{
6464
if (captured is { Process: { HasExited: false } })
65-
captured.Process.Kill();
65+
captured.Process.Kill(true);
6666
}
6767
});
6868
}

src/ViewModels/CommitDetail.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,22 @@ private void Refresh()
523523
Task.Run(async () =>
524524
{
525525
var max = Preferences.Instance.MaxHistoryCommits;
526-
var cmd = new Commands.QueryCommitChildren(_repo.FullPath, _commit.SHA, max) { CancellationToken = token };
527-
var children = await cmd.GetResultAsync().ConfigureAwait(false);
526+
var children = await new Commands.QueryCommitChildren(_repo.FullPath, _commit.SHA, max)
527+
.WithCancellation(token)
528+
.GetResultAsync()
529+
.ConfigureAwait(false);
528530
if (!token.IsCancellationRequested)
529531
Dispatcher.UIThread.Post(() => Children = children);
530532
}, token);
531533
}
532534

533535
Task.Run(async () =>
534536
{
535-
var cmd = new Commands.CompareRevisions(_repo.FullPath, _commit.FirstParentToCompare, _commit.SHA) { CancellationToken = token };
536-
var changes = await cmd.ReadAsync().ConfigureAwait(false);
537+
var changes = await new Commands.CompareRevisions(_repo.FullPath, _commit.FirstParentToCompare, _commit.SHA)
538+
.WithCancellation(token)
539+
.ReadAsync()
540+
.ConfigureAwait(false);
541+
537542
var visible = changes;
538543
if (!string.IsNullOrWhiteSpace(_searchChangeFilter))
539544
{

0 commit comments

Comments
 (0)