From 0110874ecad4800e40e057201d0b18d5a79e5dd7 Mon Sep 17 00:00:00 2001 From: n9 Date: Tue, 8 Feb 2022 21:00:09 +0100 Subject: [PATCH] Add GetQueueElements to AsyncQueue (#986) --- src/Microsoft.VisualStudio.Threading/AsyncQueue`1.cs | 11 +++++++++++ .../netstandard2.0/PublicAPI.Unshipped.txt | 1 + .../AsyncQueueTests.cs | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/Microsoft.VisualStudio.Threading/AsyncQueue`1.cs b/src/Microsoft.VisualStudio.Threading/AsyncQueue`1.cs index fea615b3f..691f0686d 100644 --- a/src/Microsoft.VisualStudio.Threading/AsyncQueue`1.cs +++ b/src/Microsoft.VisualStudio.Threading/AsyncQueue`1.cs @@ -81,6 +81,17 @@ public int Count } } + /// + /// Returns the list of elements currently in the queue. + /// + public IReadOnlyList GetQueueElements() + { + lock (this.SyncRoot) + { + return (IReadOnlyList?)this.queueElements?.ToList() ?? Array.Empty(); + } + } + /// /// Gets a value indicating whether the queue has completed. /// diff --git a/src/Microsoft.VisualStudio.Threading/netstandard2.0/PublicAPI.Unshipped.txt b/src/Microsoft.VisualStudio.Threading/netstandard2.0/PublicAPI.Unshipped.txt index e85d3c718..e32738033 100644 --- a/src/Microsoft.VisualStudio.Threading/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/Microsoft.VisualStudio.Threading/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,3 +1,4 @@ +Microsoft.VisualStudio.Threading.AsyncQueue.GetQueueElements() -> System.Collections.Generic.IReadOnlyList! Microsoft.VisualStudio.Threading.AsyncReaderWriterLock.AsyncReaderWriterLock(Microsoft.VisualStudio.Threading.JoinableTaskContext? joinableTaskContext, bool captureDiagnostics = false) -> void Microsoft.VisualStudio.Threading.AsyncReaderWriterResourceLock.AsyncReaderWriterResourceLock(Microsoft.VisualStudio.Threading.JoinableTaskContext? joinableTaskContext, bool captureDiagnostics) -> void Microsoft.VisualStudio.Threading.JoinableTaskContext.IsMainThreadMaybeBlocked() -> bool diff --git a/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs b/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs index a039a09eb..a18365900 100644 --- a/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Tests/AsyncQueueTests.cs @@ -25,6 +25,7 @@ public void JustInitialized() Assert.Equal(0, this.queue.Count); Assert.True(this.queue.IsEmpty); Assert.False(this.queue.Completion.IsCompleted); + Assert.Equal(0, this.queue.GetQueueElements().Count); } [Fact] @@ -34,6 +35,7 @@ public void Enqueue() this.queue.Enqueue(value); Assert.Equal(1, this.queue.Count); Assert.False(this.queue.IsEmpty); + Assert.Equal(1, this.queue.GetQueueElements().Count); } [Fact] @@ -43,6 +45,7 @@ public void TryEnqueue() Assert.True(this.queue.TryEnqueue(value)); Assert.Equal(1, this.queue.Count); Assert.False(this.queue.IsEmpty); + Assert.Equal(1, this.queue.GetQueueElements().Count); } [Fact]