Method BeginRequestAsync
- Namespace
- IntentSharp.Specialist
- Assembly
- IntentSharp.Specialist.dll
BeginRequestAsync(string, string, int, DateTimeOffset, CancellationToken)
Called by the runtime before it sends a request, to decide who sends it: returns the ticket when one is already
recorded for the intent and request hash; the hourly limit when the intent had maxRequestsPerHour
requests in the hour before now; that another caller is sending it; or that this caller sends
it, in which case the request is recorded at now and counts toward the limit. The default reads
the ticket and the count and then records the request, which is not atomic: a store that several processes share
overrides it so that one of them sends each request and the limit holds across them, as
DocumentSpecialistStore does.
public ValueTask<SpecialistRequestClaim> BeginRequestAsync(string intentName, string requestHash, int maxRequestsPerHour, DateTimeOffset now, CancellationToken cancellationToken)
Parameters
intentNamestringThe intent's name.
requestHashstringThe request hash.
maxRequestsPerHourintThe most requests allowed for the intent in any hour.
nowDateTimeOffsetThe time of the request.
cancellationTokenCancellationTokenCancels the call.
Returns
- ValueTask<SpecialistRequestClaim>
Remarks
Of several callers that begin one request at once, on this store or in other processes on the same document store, exactly one is told to send it; the others are told it is in progress until its ticket is recorded. The hourly count and the new request's time are read and written together, so the limit holds across processes.