From bebe86dd5d8fee45dedae05024c70c0082c4ca8a Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 21 Mar 2025 10:29:45 +0800 Subject: [PATCH] Improve query async local function --- Flow.Launcher/ViewModel/MainViewModel.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 6a8eb3761..3ed0d29d9 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1207,19 +1207,19 @@ namespace Flow.Launcher.ViewModel } // Local function - async ValueTask QueryTaskAsync(PluginPair plugin, bool reSelect = true) + async Task QueryTaskAsync(bool searchDelay, PluginPair plugin, bool reSelect, CancellationToken token) + { + if (!searchDelay) { // Since it is wrapped within a ThreadPool Thread, the synchronous context is null // Task.Yield will force it to run in ThreadPool await Task.Yield(); - - if (_updateSource.Token.IsCancellationRequested) - return; + } IReadOnlyList results = - await PluginManager.QueryForPluginAsync(plugin, query, _updateSource.Token); + await PluginManager.QueryForPluginAsync(plugin, query, token); - if (_updateSource.Token.IsCancellationRequested) + if (token.IsCancellationRequested) return; IReadOnlyList resultsCopy; @@ -1230,11 +1230,11 @@ namespace Flow.Launcher.ViewModel else { // make a copy of results to avoid possible issue that FL changes some properties of the records, like score, etc. - resultsCopy = DeepCloneResults(results); + resultsCopy = DeepCloneResults(results, token); } if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, plugin.Metadata, query, - _updateSource.Token, reSelect))) + token, reSelect))) { Log.Error("MainViewModel", "Unable to add item to Result Update Queue"); }