How to abort(cancel) forge api after request

I am using @forge/api to get issues from jira. Because of there are more than 5000 issues i should make request in parallel. So that you can imagine i make a 200 request in parallel.

I am asking that after i make request without waiting the response, i should cancel the request.

In javascript fetch there is a way to abort it, using Abortcontroller and signal

But when i use the abort controller in forge/api it gives error
Expected signal to be an instance of AbortSignal

  const controller = new AbortController();
  const response = await api
    .asApp()
    .requestJira(
      route`/rest/api/3/project/search?expand=description,lead,issueTypes,url,projectKeys,permissions,insight&startAt=${startAt}&maxResults=500`,
      {
        signal:controller.signal,
        headers: {
          Accept: "application/json",
        },
      }
    );

Welcome @FratDoan !

Are you using Custom UI or UI Kit in your code? I ask because in Forge, there’s a “bridge” between the runtime and the browser, and an AbortSignal would not be something that can cross that bridge.

As a workaround, try wrapping these calls in a custom Promise, with a setTimeout call to reject that Promise. For example:

new Promise((resolve, reject) => {
   setTimeout(() => reject(), 5000);
   const response = await api.....
   resolve(response);
});
1 Like