Skip to content

Extend SemaphoreSlim WaitAsync millisecond bound to Timer.MaxSupportedTimeout to match Timer and other APIs #116877

Open
@prvyk

Description

@prvyk

Currently, SemaphoreSlim WaitAsync limits itself to int.MaxValue milliseconds. Yet the underlying APIs support (almost) the uint full range, as do CancellationTokenSource and Task.Delay (see #43708).

SemaphoreSlim WaitAsync's range should be extended to match the other APIs to be more consistent and for the same reasons Task.Delay was extended to support the full range, e.g. supporting timeouts for a full month.

Real world use case:

microsoft/garnet implements RESP blocking commands using SemaphoreSlim.WaitAsync. Most implementations accept even large timeouts than int.MaxValue milliseconds, UINT32.MaxValue - 1 is more compatible with existing practice.

Example:

                SemaphoreSlim slim = new(0, 1);
                Console.WriteLine("start");
                await slim.WaitAsync(TimeSpan.FromDays(30));
                Console.WriteLine("do something");

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions