Skip to content

Commit bfaff5c

Browse files
committed
Improve semaphore usage and logging clarity
Added comments in `EverythingAPI.cs` and `Main.cs` to explain why `CancellationToken` is not directly passed to semaphore locks, preventing unexpected `OperationCanceledException`. Updated debug log messages in `Main.cs` for better clarity, including changing "Start handling programs" to "Start querying programs". Removed redundant log messages to improve logging consistency.
1 parent 30d7f67 commit bfaff5c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public static bool IsFastSortOption(EverythingSortOption sortOption)
4848

4949
public static async ValueTask<bool> IsEverythingRunningAsync(CancellationToken token = default)
5050
{
51+
// We do not directly pass token here, but we check IsCancellationRequested inside the lock
52+
// So that it will not raise OperationCanceledException, which is not expected by the caller.`
5153
await _semaphore.WaitAsync();
5254

5355
try

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
8484
{
8585
var resultList = await Task.Run(async () =>
8686
{
87+
// We do not directly pass token here, but we check IsCancellationRequested inside the lock
88+
// So that it will not raise OperationCanceledException, which is not expected by the caller.`
8789
Context.API.LogDebug(ClassName, "Preparing win32 programs");
8890
List<Win32> win32s;
8991
await _win32sLock.WaitAsync();
@@ -97,6 +99,8 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
9799
_win32sLock.Release();
98100
}
99101

102+
// We do not directly pass token here, but we check IsCancellationRequested inside the lock
103+
// So that it will not raise OperationCanceledException, which is not expected by the caller.`
100104
Context.API.LogDebug(ClassName, "Preparing UWP programs");
101105
List<UWPApp> uwps;
102106
await _uwpsLock.WaitAsync();
@@ -110,7 +114,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
110114
_uwpsLock.Release();
111115
}
112116

113-
Context.API.LogDebug(ClassName, "Start hanlding programs");
117+
Context.API.LogDebug(ClassName, "Start querying programs");
114118
try
115119
{
116120
// Collect all UWP Windows app directories
@@ -324,7 +328,6 @@ static void WatchProgramUpdate()
324328

325329
public static async Task IndexWin32ProgramsAsync()
326330
{
327-
Context.API.LogDebug(ClassName, "Prepare indexing Win32 programs");
328331
await _win32sLock.WaitAsync();
329332
Context.API.LogDebug(ClassName, "Start indexing Win32 programs");
330333
try
@@ -354,7 +357,6 @@ public static async Task IndexWin32ProgramsAsync()
354357

355358
public static async Task IndexUwpProgramsAsync()
356359
{
357-
Context.API.LogDebug(ClassName, "Prepare indexing Uwp programs");
358360
await _uwpsLock.WaitAsync();
359361
Context.API.LogDebug(ClassName, "Start indexing Uwp programs");
360362
try

0 commit comments

Comments
 (0)