Table of Contents

NotableDateServiceAsyncExtensions Class

Definition

Namespace
Bodu.Globalization.Calendar
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
NotableDateServiceAsyncExtensions.cs

Provides asynchronous streaming projections over INotableDateService, yielding occurrences incrementally for large multi-year range queries.

public static class NotableDateServiceAsyncExtensions
Inheritance
NotableDateServiceAsyncExtensions
Inherited Members

Examples

INotableDateService service = AmericasCalendarData.CreateService("US");
DateRange decade = new(new DateOnly(2020, 1, 1), new DateOnly(2029, 12, 31));

await foreach (NotableDate occurrence in service.ResolveAsync(decade, "US", cancellationToken: token))
{
    Console.WriteLine($"{occurrence.Date:yyyy-MM-dd} {occurrence.DisplayName}");
}

Remarks

Notable-date resolution is synchronous, CPU-bound work - there is no I/O to overlap - so these projections do not offload to the thread pool. Instead the requested range is resolved one civil year at a time, occurrences are yielded as each year completes, and the iterator yields control cooperatively between years so a consumer awaiting the sequence observes progress (and cancellation) at year granularity rather than only after the whole range has resolved.

The streamed sequence is element-for-element identical to the corresponding synchronous Resolve(DateRange, string) call over the same range: the same occurrences, in the same date-then-identity order, with a multi-day occurrence spanning a year boundary yielded exactly once.

Methods

ResolveAsync(INotableDateService, DateRange, string, NotableDateFilter?, CancellationToken)

Resolves the notable-date occurrences emitted in a date range for the requested territory as an asynchronous stream, optionally restricted to occurrences matching a filter.

public static IAsyncEnumerable<NotableDate> ResolveAsync(this INotableDateService service, DateRange range, string territory, NotableDateFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

service INotableDateService

The service used to resolve notable dates.

range DateRange

The inclusive date range to resolve.

territory string

The requested territory code.

filter NotableDateFilter

The filter that emitted occurrences must satisfy, or null for all.

cancellationToken CancellationToken

The token observed between resolved years to cancel the stream.

Returns

IAsyncEnumerable<NotableDate>

An asynchronous sequence of the occurrences emitted in the range, ordered by date then identity - the same occurrences the synchronous range overloads return.

Remarks

Arguments are validated eagerly, when the method is called; resolution work begins on the first MoveNextAsync. Cancellation is observed between civil years, so a request over a single year cancels only before or after that year resolves.

Exceptions

ArgumentNullException

service or territory is null.

ArgumentOutOfRangeException

range has a start date later than its end date.

OperationCanceledException

cancellationToken (or a token supplied via WithCancellation) is cancelled while the stream is being enumerated.

Applies to

ProductVersions
.NET8, 10

See Also