Skip to content

Commit d5d660e

Browse files
committed
Test for empty list
1 parent 905a97d commit d5d660e

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,7 @@ async Task UpdateActionAsync()
214214
await Task.Delay(20);
215215
while (channelReader.TryRead(out var item))
216216
{
217-
if (item.shouldClearExistingResults)
218-
{
219-
cancelIndex++;
220-
if (cancelIndex > 1)
221-
{
222-
// Assume one task for clearing existing results is cancelled
223-
continue;
224-
}
225-
}
226-
227-
228-
if (!item.Token.IsCancellationRequested)
217+
if (item.shouldClearExistingResults || !item.Token.IsCancellationRequested)
229218
queue[item.ID] = item;
230219
}
231220

@@ -1450,6 +1439,16 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
14501439
_lastQuery = query;
14511440
_previousIsHomeQuery = currentIsHomeQuery;
14521441

1442+
// Test: Assume first query task for clearing existing results is cancelled
1443+
if (shouldClearExistingResults)
1444+
{
1445+
cancelIndex++;
1446+
if (cancelIndex == 2)
1447+
{
1448+
currentUpdateSource.Cancel();
1449+
}
1450+
}
1451+
14531452
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query,
14541453
token, reSelect, shouldClearExistingResults)))
14551454
{
@@ -1874,7 +1873,9 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
18741873
{
18751874
if (!resultsForUpdates.Any())
18761875
return;
1876+
18771877
CancellationToken token;
1878+
var shouldClearExistingResults = resultsForUpdates.Any(r => r.shouldClearExistingResults);
18781879

18791880
try
18801881
{
@@ -1936,7 +1937,7 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
19361937
// it should be the same for all results
19371938
bool reSelect = resultsForUpdates.First().ReSelectFirstResult;
19381939

1939-
Results.AddResults(resultsForUpdates, token, reSelect);
1940+
Results.AddResults(resultsForUpdates, token, reSelect, shouldClearExistingResults);
19401941
}
19411942

19421943
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,21 @@ public void AddResults(List<Result> newRawResults, string resultId)
185185
/// <summary>
186186
/// To avoid deadlock, this method should not called from main thread
187187
/// </summary>
188-
public void AddResults(ICollection<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
188+
public void AddResults(ICollection<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true, bool shouldClearExistingResults = false)
189189
{
190190
var newResults = NewResults(resultsForUpdates);
191191

192192
if (token.IsCancellationRequested)
193-
return;
193+
{
194+
if (shouldClearExistingResults)
195+
{
196+
newResults = new List<ResultViewModel>();
197+
}
198+
else
199+
{
200+
return;
201+
}
202+
}
194203

195204
UpdateResults(newResults, reselect, token);
196205
}

0 commit comments

Comments
 (0)