Skip to content

[API Proposal]: Remove setter of Capacity Property in the BoundedChannelOptions class #68936

@ArminShoeibi

Description

@ArminShoeibi

Background and motivation

Hi there folks.
We have repeated one condition 2 times, first in the constructor then in the body of set accessor.

the constructor wants a value for capacity , and then we can override that in the object initialization.
image

API Proposal

public sealed class BoundedChannelOptions : ChannelOptions
{
    /// <summary>The behavior incurred by write operations when the channel is full.</summary>
    private BoundedChannelFullMode _mode = BoundedChannelFullMode.Wait;

    /// <summary>Initializes the options.</summary>
    /// <param name="capacity">The maximum number of items the bounded channel may store.</param>
    public BoundedChannelOptions(int capacity)
    {
        if (capacity < 1)
        {
            throw new ArgumentOutOfRangeException(nameof(capacity));
        }
        Capacity = capacity;
    }

    /// <summary>Gets or sets the maximum number of items the bounded channel may store.</summary>
    public int Capacity { get; }

    /// <summary>Gets or sets the behavior incurred by write operations when the channel is full.</summary>
    public BoundedChannelFullMode FullMode
    {
        get => _mode;
        set
        {
            switch (value)
            {
                case BoundedChannelFullMode.Wait:
                case BoundedChannelFullMode.DropNewest:
                case BoundedChannelFullMode.DropOldest:
                case BoundedChannelFullMode.DropWrite:
                    _mode = value;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(value));
            }
        }
    }
}

API Usage

We won't have capacity property in object initialization
image

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions