Current State
Currently, if developers want to control operation cancellation through CancellationToken
, they are a little stuck, since the HandleAsync()
method doesn't have a CancellationToken
parameter.
MVC auto injects these values if they are present.
Motivation
In an app that renders HTML for the browser, this might not be as important, but in client side JavaScript applications, it's not uncommon for for a user to interact with multiple parts of the UI in quick succession (like typing in a search box) that would cause previous XHR requests to be canceled since those responses would be discarded by the client anyway - it's only interested in the latest response.
ASP.NET Core will still handle the cancellation and not send the response, but the developer's pipeline of operations continue to execute on the previous request thread while the newer request is handled.
Many external service libraries (DB, HTTP) accept CancellationToken
s to halt operations.
Solution
It would be nice to be able to support cancellation from end-to-end with ApiEndpoints.
I believe we'd need to change the HandleAsync()
API to accept a CancellationToken token
as the last parameter, which means a breaking change.
Thoughts
I'd be willing to PR this if you are interested in the idea.
I'm also wondering, since it would be a breaking change, if there were any other solutions to problems you'd like to roll in with it, like supporting multiple method params (not sure how... maybe multiple generics like the BCL does it with Func<>
and Action<>
?)