-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal] Channel.CreateUnboundedPrioritized #62761
Comments
Tagging subscribers to this area: @dotnet/area-system-threading-channels Issue DetailsJust 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 reader 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 Referencing cc: @stephentoub
|
A potential simple workaround: Note: the base channel types are |
Thanks @gfoidl I was thinking similar to your scheme but have around 6 priority levels. I noticed the abstracts and thinking that might be the route I'll have to take. |
Doesn't look like we have something like |
@buyaa-n Thanks for the response. I actually don't have anything specific in mind and probably a semi-combination of both their features would help. I'll add later if I something specific comes up. Thanks again. |
Hi, are there any updates on this? |
To add on the above, I would really like to have PriorityQueue-like Channel implementation. For example, this class PriorityQueue<TElement,TPriority> would have made perfect job if only it had the goods of Channel:
|
This is approximately what I think this would look like: 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; }
+} Any feedback? |
@stephentoub really happy to see this Given the implementation is done, I'd be happy to start using it (now..). Many thanks ! |
It is not in .NET 8. If it gets added, it would be at the earliest in .NET 9. But you can copy/paste the code from my branch into your project and tweak it to make it compile. |
@stephentoub, are you sure I can? It relies on Actually I have a real of this implementation, if some hacks need to be made in order to make it work, please tell me. Thanks Stephen |
Those are all part of its implementation. You would copy those, too. |
Looks good as proposed. 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; }
+} |
EDITED by @stephentoub on 2/17/2024:
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 byChannels
.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
The text was updated successfully, but these errors were encountered: