NotableDateServiceAsyncExtensions Class
Definition
- Namespace
- Bodu.Globalization.Calendar
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
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
serviceINotableDateServiceThe service used to resolve notable dates.
rangeDateRangeThe inclusive date range to resolve.
territorystringThe requested territory code.
filterNotableDateFilterThe filter that emitted occurrences must satisfy, or null for all.
cancellationTokenCancellationTokenThe 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
serviceorterritoryis null.- ArgumentOutOfRangeException
rangehas a start date later than its end date.- OperationCanceledException
cancellationToken(or a token supplied viaWithCancellation) is cancelled while the stream is being enumerated.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |