dotnet / dotnet/runtime

[API Proposal]: ChannelOptions.ProcessingOrder

Open
#125,923 3 comments 1 reaction 0 assignees View on GitHub
api-suggestion area-System.Threading.Channels help wanted
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Background and motivation

Today's Channels are essentially Queue-based.
In our application, this causes us to process information breadth-first which, for us, is much more memory intensive.
A stack-based method would let us process things depth-first and would drastically reduce memory.

### API Proposal

```csharp
namespace System.Threading.Channels;

public enum ChannelProcessingOrder {
Queue,
Stack,
}

public class ChannelOptions
{
public ChannelProcessingOrder ProcessingOrder {get; set;} = ChannelProcessingOrder,Queue;
}
```

### API Usage

```csharp
var Options = new BoundedChannelOptions(){ //Inherits from ChannelOptions
ProcessingOrder = ChannelProcessingOrder.Stack,
};

```

### Alternative Designs

Channels could be adapted so that the backing collection type could be provided. This would allow priority-queue scenarios. However, this might be overkill and could likely create a surface area for bugs.

### Risks

Because of threading and concurrency, the order is not strictly guaranteed to be stack or queue. It is actually stack-ish or queue-ish. Someone might think the order is strictly guaranteed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.