fix concurrency issue (potentially)

This commit is contained in:
Hongtao Zhang 2022-12-03 13:44:43 -06:00
parent 605db6095a
commit 4a0ee9b4fc
No known key found for this signature in database
GPG key ID: 75F655B91C7AC9BB

View file

@ -19,9 +19,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
private const int BufferSize = 4096;
private static SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private static SemaphoreSlim _semaphore = new(1, 1);
// cached buffer to remove redundant allocations.
private static readonly StringBuilder buffer = new StringBuilder(BufferSize);
private static readonly StringBuilder buffer = new(BufferSize);
public enum StateCode
{
@ -118,14 +118,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
if (option.MaxCount < 0)
throw new ArgumentOutOfRangeException(nameof(option.MaxCount), option.MaxCount, "MaxCount must be greater than or equal to 0");
await _semaphore.WaitAsync(token);
if (token.IsCancellationRequested)
yield break;
try
{
await _semaphore.WaitAsync(token);
if (token.IsCancellationRequested)
yield break;
if (option.Keyword.StartsWith("@"))
{