soxa icon indicating copy to clipboard operation
soxa copied to clipboard

Config.timeout not working

Open jupegarnica opened this issue 4 years ago • 1 comments

The parameter timeout it is not working either at instance creation neither as options during calling soxa.get(url, options)

I make my own cancel logic using a cancelation token, but the documentation is not rigth. I had to import CancelToken from /src/cancel/CancelToken.ts. It is not in soxa instance.

import { soxa } from 'https://deno.land/x/[email protected]/mod.ts';
import { CancelToken } from 'https://deno.land/x/[email protected]/src/cancel/CancelToken.ts';
import { REQUEST_TIMEOUT } from './config.ts';

export async function get(url: string): Promise<any> {
  let cancel: Function;
  const id: number = setTimeout(() => {
    cancel('TIMEOUT ' + REQUEST_TIMEOUT);
  }, REQUEST_TIMEOUT);

  const response: any = await soxa
    .get(url, {
      cancelToken: new CancelToken(
        (c: Function) => (cancel = c),
      ),
    })
    .finally(() => clearTimeout(id));
  return response;
}

jupegarnica avatar Dec 06 '20 08:12 jupegarnica

Actually, this approach is not working anyway. Just to let you know.

jupegarnica avatar Dec 08 '20 14:12 jupegarnica