Skip to content

Commit bebe86d

Browse files
committed
Improve query async local function
1 parent 2619851 commit bebe86d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,19 +1207,19 @@ private async Task QueryResultsAsync(int? searchDelay, bool isReQuery = false, b
12071207
}
12081208

12091209
// Local function
1210-
async ValueTask QueryTaskAsync(PluginPair plugin, bool reSelect = true)
1210+
async Task QueryTaskAsync(bool searchDelay, PluginPair plugin, bool reSelect, CancellationToken token)
1211+
{
1212+
if (!searchDelay)
12111213
{
12121214
// Since it is wrapped within a ThreadPool Thread, the synchronous context is null
12131215
// Task.Yield will force it to run in ThreadPool
12141216
await Task.Yield();
1215-
1216-
if (_updateSource.Token.IsCancellationRequested)
1217-
return;
1217+
}
12181218

12191219
IReadOnlyList<Result> results =
1220-
await PluginManager.QueryForPluginAsync(plugin, query, _updateSource.Token);
1220+
await PluginManager.QueryForPluginAsync(plugin, query, token);
12211221

1222-
if (_updateSource.Token.IsCancellationRequested)
1222+
if (token.IsCancellationRequested)
12231223
return;
12241224

12251225
IReadOnlyList<Result> resultsCopy;
@@ -1230,11 +1230,11 @@ async ValueTask QueryTaskAsync(PluginPair plugin, bool reSelect = true)
12301230
else
12311231
{
12321232
// make a copy of results to avoid possible issue that FL changes some properties of the records, like score, etc.
1233-
resultsCopy = DeepCloneResults(results);
1233+
resultsCopy = DeepCloneResults(results, token);
12341234
}
12351235

12361236
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query,
1237-
_updateSource.Token, reSelect)))
1237+
token, reSelect)))
12381238
{
12391239
Log.Error("MainViewModel", "Unable to add item to Result Update Queue");
12401240
}

0 commit comments

Comments
 (0)