Open
Description
Background and motivation
This is a follow up to the UnboundedPrioritizedChannel #62761
It would be nice to have a prioritized bounded channel so that consumers could work on the highest priority item in a channel while still being able to limit the number of items held in the channel.
cc: @stephentoub
API Proposal
namespace System.Threading.Channels;
public class Channel
{
+ public static Channel<T> CreateBoundedPrioritized<T>();
+ public static Channel<T> CreateBoundedPrioritized<T>(BoundedPrioritizedChannelOptions<T> options);
}
+public sealed partial class BoundedPrioritizedChannelOptions<T> : BoundedChannelOptions
+{
+ public System.Collections.Generic.IComparer<T>? Comparer { get; set; }
+}
API Usage
var queue = Channel.CreateBoundedPrioritized<Foo>(100);
Alternative Designs
No response
Risks
I may be hard to understand what happens when items with higher priority are written to the channel when the channel has reached capacity, but I don't think there is ant other option that is valid.