Skip to content

[API Proposal] Channel.CreateUnboundedPrioritized #62761

Closed
@shaggygi

Description

@shaggygi

EDITED by @stephentoub on 2/17/2024:

namespace System.Threading.Channels;

public class Channel
{
+   public static Channel<T> CreateUnboundedPrioritized<T>();
+   public static Channel<T> CreateUnboundedPrioritized<T>(UnboundedPrioritizedChannelOptions<T> options);
}
+public sealed partial class UnboundedPrioritizedChannelOptions<T> : ChannelOptions
+{
+   public System.Collections.Generic.IComparer<T>? Comparer { get; set; }
+}

Just wondering if anyone knows if a priority channel is available or a potential idea of adding to System.Threading.Channels. Something similar to Bounded/Unbounded channels with Reader/Writer along with priority capabilities. Meaning, you could write a large set of items to a channel in any order, but the reader would be sorted/read by a prioritized item.

I guess when it boils down to it I could use the PriorityQueue, but I do like the features provided by Channels.

Referencing
https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.priorityqueue-2?view=net-6.0
https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels/

cc: @stephentoub

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Threading.Channelsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions