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")); + } } ///