Skip to content

Commit

Permalink
Add ConcurrentQueue Clear (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Nov 7, 2024
1 parent bbae6a8 commit 94b3256
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**API count: 401**
**API count: 402**
5 changes: 5 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
* `TValue GetOrAdd<TKey, TValue, TArg>(TKey, Func<TKey, TArg, TValue>, TArg) where TKey : notnull` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd#system-collections-concurrent-concurrentdictionary-2-getoradd-1(-0-system-func((-0-0-1))-0))


#### ConcurrentQueue<T>

* `void Clear<T>()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentqueue-1.clear)


#### DateOnly

* `bool TryFormat(Span<char>, int, ReadOnlySpan<char>, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.dateonly.tryformat)
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`


**API count: 401**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
**API count: 402**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->


**See [Milestones](../../milestones?state=closed) for release notes.**
Expand Down Expand Up @@ -485,6 +485,11 @@ The class `Polyfill` includes the following extension methods:
* `TValue GetOrAdd<TKey, TValue, TArg>(TKey, Func<TKey, TArg, TValue>, TArg) where TKey : notnull` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd#system-collections-concurrent-concurrentdictionary-2-getoradd-1(-0-system-func((-0-0-1))-0))


#### ConcurrentQueue<T>

* `void Clear<T>()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentqueue-1.clear)


#### DateOnly

* `bool TryFormat(Span<char>, int, ReadOnlySpan<char>, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.dateonly.tryformat)
Expand Down
6 changes: 6 additions & 0 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ void ConcurrentBag_Methods()
bag.Clear();
}

void ConcurrentQueue_Methods()
{
var bag = new ConcurrentQueue<string>();
bag.Clear();
}

void Dictionary_Methods()
{
var dictionary = new Dictionary<string, string?> { { "key", "value" } };
Expand Down
5 changes: 0 additions & 5 deletions src/Polyfill/Polyfill_ConcurrentBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ static partial class Polyfill
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentbag-1.clear")]
public static void Clear<T>(this ConcurrentBag<T> target)
{
if (target is null)
{
throw new ArgumentNullException(nameof(target));
}

while (!target.IsEmpty)
{
target.TryTake(out _);
Expand Down
23 changes: 23 additions & 0 deletions src/Polyfill/Polyfill_ConcurrentQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <auto-generated />
#pragma warning disable

#if NETFRAMEWORK || NETSTANDARD2_0

namespace Polyfills;

using System;
using System.Collections.Concurrent;
using Link = System.ComponentModel.DescriptionAttribute;

static partial class Polyfill
{
/// <summary>
/// Removes all values from the <see cref="ConcurrentQueue{T}"/>.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentqueue-1.clear")]
public static void Clear<T>(this ConcurrentQueue<T> target)
{
while (target.TryDequeue(out _));
}
}
#endif
11 changes: 11 additions & 0 deletions src/Tests/PolyfillTests_ConcurrentQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
partial class PolyfillTests
{
[Test]
public void ConcurrentQueueClear()
{
var bag = new ConcurrentQueue<string>();
bag.Enqueue("Hello");
bag.Clear();
Assert.AreEqual(0, bag.Count);
}
}

0 comments on commit 94b3256

Please sign in to comment.