Skip to content

Commit

Permalink
Add GetQueueElements to AsyncQueue<T> (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
n9 committed Feb 8, 2022
1 parent 26b09cb commit 0110874
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Microsoft.VisualStudio.Threading/AsyncQueue`1.cs
Expand Up @@ -81,6 +81,17 @@ public int Count
}
}

/// <summary>
/// Returns the list of elements currently in the queue.
/// </summary>
public IReadOnlyList<T> GetQueueElements()
{
lock (this.SyncRoot)
{
return (IReadOnlyList<T>?)this.queueElements?.ToList() ?? Array.Empty<T>();
}
}

/// <summary>
/// Gets a value indicating whether the queue has completed.
/// </summary>
Expand Down
@@ -1,3 +1,4 @@
Microsoft.VisualStudio.Threading.AsyncQueue<T>.GetQueueElements() -> System.Collections.Generic.IReadOnlyList<T>!
Microsoft.VisualStudio.Threading.AsyncReaderWriterLock.AsyncReaderWriterLock(Microsoft.VisualStudio.Threading.JoinableTaskContext? joinableTaskContext, bool captureDiagnostics = false) -> void
Microsoft.VisualStudio.Threading.AsyncReaderWriterResourceLock<TMoniker, TResource>.AsyncReaderWriterResourceLock(Microsoft.VisualStudio.Threading.JoinableTaskContext? joinableTaskContext, bool captureDiagnostics) -> void
Microsoft.VisualStudio.Threading.JoinableTaskContext.IsMainThreadMaybeBlocked() -> bool
Expand Down
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 0110874

Please sign in to comment.