Skip to content

[API Proposal] Channel.CreateBoundedPrioritized #101292

Open
@andreas-eriksson

Description

@andreas-eriksson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Threading.Channelsneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions