Skip to content

[Feature Request] Support CancellationToken in all Asynchronous Methods #77

@EthanDelong

Description

@EthanDelong

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

  1. 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);
  1. Pass the token into any inner async calls, such as HttpClient.SendAsync.

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions