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

Looks like fetch from ‘@forge/api’ is not compatible with standard AbortSignal class.
This example AbortSignal: timeout() static method - Web APIs | MDN is not working properly with error:

Type 'AbortSignal' is not assignable to type 'import("/Users/pisklenov/projects/host-checker/node_modules/@types/node-fetch/externals").AbortSignal'.
  Types of property 'onabort' are incompatible.
    Type '((this: AbortSignal, ev: Event) => any) | null' is not assignable to type '((this: AbortSignal, event: any) => any) | null'.
      Type '(this: AbortSignal, ev: Event) => any' is not assignable to type '(this: AbortSignal, event: any) => any'.
        The 'this' types of each signature are incompatible.
          Property 'any' is missing in type 'import("/Users/pisklenov/projects/host-checker/node_modules/@types/node-fetch/externals").AbortSignal' but required in type 'AbortSignal'.ts(2322)
lib.dom.iterable.d.ts(25, 5): 'any' is declared here.