From 67bdec857085f96f9f734a85ae4044c166f1a078 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Tue, 8 Jul 2025 21:26:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BF=A1=E5=8F=B7?= =?UTF-8?q?=E9=87=8F=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/Common/SemaphorePool.cs | 35 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/server/src/Common/SemaphorePool.cs b/server/src/Common/SemaphorePool.cs index 34ec9fb..0840274 100644 --- a/server/src/Common/SemaphorePool.cs +++ b/server/src/Common/SemaphorePool.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using DotNext; namespace Common; @@ -65,26 +66,38 @@ public class SemaphorePool /// [TODO:description] /// /// [TODO:return] - public void Wait() + public Result Wait() { - WaitAsync().Wait(); + semaphore.Wait(); + + int pop; + if (queue.TryDequeue(out pop)) + { + return pop; + } + else + { + return new(new Exception($"TODO")); + } } /// /// [TODO:description] /// /// [TODO:return] - public Task WaitAsync() + public async ValueTask> WaitAsync() { - var tcs = new TaskCompletionSource(); - queue.Enqueue(tcs); - semaphore.WaitAsync().ContinueWith(t => + await semaphore.WaitAsync(); + + int pop; + if (queue.TryDequeue(out pop)) { - TaskCompletionSource popped; - if (queue.TryDequeue(out popped)) - popped.SetResult(true); - }); - return tcs.Task; + return pop; + } + else + { + return new(new Exception($"TODO")); + } } ///