Skip to content

Add CancellationToken support to all async methods #40

Description

@DaraOladapo

Description

No method in the library accepts a CancellationToken. This means callers cannot cancel in-flight requests (e.g. when a user navigates away, a timeout fires, or a service shuts down), and the underlying HttpClient calls that do support cancellation cannot be wired up.

Proposed Change

Add an optional CancellationToken parameter (defaulting to CancellationToken.None) to every public async method:

// Before
public static async Task<HttpResponseMessage> GetAsync(string Route)

// After
public static async Task<HttpResponseMessage> GetAsync(string Route, CancellationToken cancellationToken = default)

Pass it through to the underlying HttpClient call:

var httpResponse = await httpClient.GetAsync(new Uri(Route), cancellationToken);

Scope

All public async methods across Get.cs, Post.cs, Put.cs, Patch.cs, Delete.cs.

Acceptance Criteria

  • Every public async method has a CancellationToken cancellationToken = default parameter
  • The token is passed to the underlying HttpClient method
  • Change is non-breaking (default value means no call-site updates required)
  • Tests cover cancellation (assert OperationCanceledException is thrown when token is cancelled)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions