Description
Currently, the asynchronous methods in the Clerk.BackendAPI project (such as Users.ListAsync) do not accept a CancellationToken.
Motivation
These tokens are necessary to prevent tasks from getting stuck on I/O operations when a task is cancelled from an external source.
Proposed Solution
- Update the current method signatures to accept an optional CancellationToken type parameter. For example:
Task<GetUserResponse> GetAsync(string userId, RetryConfig? retryConfig = null, CancellationToken cancellationToken = default);
-
Pass the token into any inner async calls, such as HttpClient.SendAsync.
-
Call CancellationToken.ThrowIfCancellationRequested in the beginning of methods, inside loops, and prior to any heavy I/O (unless it already accepts a CT, like HttpClient).
Alternatives Considered
Using wrappers like Task.WhenAny(...) or .WaitAsync(...) to cancel the task entirely when a cancellation is requested.
Setting timeouts on the client-specific requests to prevent potential hangs.
Testing
Use a mock of the client (I think this is ISpeakEasyClient?) to fake a long-running request, and explicitly call a cancellation on our token. Ensure that it throws an OperationCanceledException.
Description
Currently, the asynchronous methods in the Clerk.BackendAPI project (such as
Users.ListAsync)do not accept aCancellationToken.Motivation
These tokens are necessary to prevent tasks from getting stuck on I/O operations when a task is cancelled from an external source.
Proposed Solution
Pass the token into any inner async calls, such as
HttpClient.SendAsync.Call
CancellationToken.ThrowIfCancellationRequestedin the beginning of methods, inside loops, and prior to any heavy I/O (unless it already accepts a CT, like HttpClient).Alternatives Considered
Using wrappers like
Task.WhenAny(...)or.WaitAsync(...)to cancel the task entirely when a cancellation is requested.Setting timeouts on the client-specific requests to prevent potential hangs.
Testing
Use a mock of the client (I think this is
ISpeakEasyClient?) to fake a long-running request, and explicitly call a cancellation on our token. Ensure that it throws anOperationCanceledException.