Implement deferred core utility parity APIs/tests and refresh tracking artifacts
This commit is contained in:
@@ -40,6 +40,24 @@ public sealed class IpQueue<T>
|
||||
/// <summary>Default maximum size of the recycled backing-list capacity.</summary>
|
||||
public const int DefaultMaxRecycleSize = 4 * 1024;
|
||||
|
||||
/// <summary>
|
||||
/// Functional option type used by <see cref="NewIPQueue"/>.
|
||||
/// Mirrors Go <c>ipQueueOpt</c>.
|
||||
/// </summary>
|
||||
public delegate void IpQueueOption(IpQueueOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Option bag used by <see cref="NewIPQueue"/>.
|
||||
/// Mirrors Go <c>ipQueueOpts</c>.
|
||||
/// </summary>
|
||||
public sealed class IpQueueOptions
|
||||
{
|
||||
public int MaxRecycleSize { get; set; } = DefaultMaxRecycleSize;
|
||||
public Func<T, ulong>? SizeCalc { get; set; }
|
||||
public ulong MaxSize { get; set; }
|
||||
public int MaxLen { get; set; }
|
||||
}
|
||||
|
||||
private long _inprogress;
|
||||
private readonly object _lock = new();
|
||||
|
||||
@@ -68,6 +86,56 @@ public sealed class IpQueue<T>
|
||||
/// <summary>Notification channel reader — wait on this to learn items were added.</summary>
|
||||
public ChannelReader<bool> Ch => _ch.Reader;
|
||||
|
||||
/// <summary>
|
||||
/// Option helper that configures maximum recycled backing-list size.
|
||||
/// Mirrors Go <c>ipqMaxRecycleSize</c>.
|
||||
/// </summary>
|
||||
public static IpQueueOption IpqMaxRecycleSize(int max) =>
|
||||
options => options.MaxRecycleSize = max;
|
||||
|
||||
/// <summary>
|
||||
/// Option helper that enables size accounting for queue elements.
|
||||
/// Mirrors Go <c>ipqSizeCalculation</c>.
|
||||
/// </summary>
|
||||
public static IpQueueOption IpqSizeCalculation(Func<T, ulong> calc) =>
|
||||
options => options.SizeCalc = calc;
|
||||
|
||||
/// <summary>
|
||||
/// Option helper that limits queue pushes by total accounted size.
|
||||
/// Mirrors Go <c>ipqLimitBySize</c>.
|
||||
/// </summary>
|
||||
public static IpQueueOption IpqLimitBySize(ulong max) =>
|
||||
options => options.MaxSize = max;
|
||||
|
||||
/// <summary>
|
||||
/// Option helper that limits queue pushes by element count.
|
||||
/// Mirrors Go <c>ipqLimitByLen</c>.
|
||||
/// </summary>
|
||||
public static IpQueueOption IpqLimitByLen(int max) =>
|
||||
options => options.MaxLen = max;
|
||||
|
||||
/// <summary>
|
||||
/// Factory wrapper for Go parity.
|
||||
/// Mirrors <c>newIPQueue</c>.
|
||||
/// </summary>
|
||||
public static IpQueue<T> NewIPQueue(
|
||||
string name,
|
||||
ConcurrentDictionary<string, object>? registry = null,
|
||||
params IpQueueOption[] options)
|
||||
{
|
||||
var opts = new IpQueueOptions();
|
||||
foreach (var option in options)
|
||||
option(opts);
|
||||
|
||||
return new IpQueue<T>(
|
||||
name,
|
||||
registry,
|
||||
opts.MaxRecycleSize,
|
||||
opts.SizeCalc,
|
||||
opts.MaxSize,
|
||||
opts.MaxLen);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new queue, optionally registering it in <paramref name="registry"/>.
|
||||
/// Mirrors <c>newIPQueue</c>.
|
||||
|
||||
Reference in New Issue
Block a user