diff --git a/libs/storage/Tsavorite/cs/src/core/Device/AsyncPool.cs b/libs/storage/Tsavorite/cs/src/core/Device/AsyncPool.cs index 4b4ab61a94..c96efb0b7e 100644 --- a/libs/storage/Tsavorite/cs/src/core/Device/AsyncPool.cs +++ b/libs/storage/Tsavorite/cs/src/core/Device/AsyncPool.cs @@ -8,16 +8,19 @@ namespace Tsavorite.core { + + + /// /// Asynchronous pool of fixed pre-filled capacity /// Supports sync get (TryGet) for fast path /// /// - public class AsyncPool : IDisposable where T : IDisposable + public class AsyncPool : IDisposable where T : IDisposable { readonly int size; readonly Func creator; - readonly SemaphoreSlim handleAvailable; + readonly SemaphoreSlim handleAvailable; readonly ConcurrentQueue itemQueue; bool disposed = false; @@ -45,12 +48,14 @@ public T Get(CancellationToken token = default) { for (; ; ) { - if (disposed) + if ( disposed) throw new TsavoriteException("Getting handle in disposed device"); if (GetOrAdd(itemQueue, out T item)) return item; + + handleAvailable.Wait(token); } } @@ -83,7 +88,7 @@ public bool TryGet(out T item) { if (disposed) { - item = default; + item = default; return false; } return GetOrAdd(itemQueue, out item);