Skip to content

Async Api Methods Should Have a CancellationToken Parameter #221

@mattscully

Description

@mattscully

Since all the API SDK methods make HTTP calls (via RestSharp), they should also allow a CancellationToken to be passed in as a parameter. Given that API calls may vary significantly in the time they take to complete (some may query for a quick status and others may download megabytes of documents), it may be quite common to have different timeout expectations for different methods. Accepting a CancellationToken would improve the API by:

  1. Allowing for a timeout to be set by method invocation while still sharing a common Configuration instance.
  2. Allowing the request to be cancelled by a user action.

It is quite common to make the CancellationToken an optional parameter, which I think would make sense here. For example

public async Task<Envelope> GetEnvelopeAsync(
      string accountId,
      string envelopeId,
      EnvelopesApi.GetEnvelopeOptions options = null,
      CancellationToken cancellationToken = default(CancellationToken))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions