← All source files

V14 / fad4e1a110e5

CalendarDelivery.cs

Lilith/Core/Calendar/CalendarDelivery.cs

Unchanged from the preceding version
CS
namespace Lilith.Core.Calendar;

public static class CalendarDelivery
{
    // Caller owns the host's conversation/narration gate, shared with scheduler delivery.
    public static async Task DrainAsync(ProviderClient provider, Func<string, CancellationToken, Task> narrate, CancellationToken ct = default)
    {
        if (provider.Calendar is not { } calendar) return;
        for (int i = 0; i < 10 && calendar.PeekNotice() is { } notice; i++)
        {
            ct.ThrowIfCancellationRequested();
            provider.RecordCalendarNotice(notice);
            await narrate(notice.Message, ct);
            calendar.CompleteNotice(notice.Id);
        }
    }
}