Skip to content

[Feature] Allow canceling individual requests #187

@groupsky

Description

@groupsky

Currently to cancel a request made by commerce-sdk-isomorphic the only way is to include AbortSignal in clientConfiguration.fetchOptions, but that uses the same signal for all requests. Although it is usable it requires to create separate client for each scope where requests may need to be canceled.

Instead if AbortSignal could be provided when executing an api call it will allow to reuse clients within subscopes and each request may have separate signal.

Example usage:

// client created globally
const client = new ShopperSearch(clientConfig)

function doSearch(query) {
  // cancel previous search in progress
  if (this.abortController) {
    this.abortController.abort()
  }

  // make new search request with new abort controller
  this.abortController = new AbortController()
  return this.client.productSearch({
    parameters: { q: query },
    headers: { authorization: /* ... */ },
    signal: this.abortController.signal,
  })
}

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