diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index 1f7421a710ac0d..eda337cd5160ed 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -19,6 +19,7 @@ import { Throttle, getThrottle } from './throttle'; import type { GotJSONOptions, GotOptions, + GotTask, HttpOptions, HttpRequestOptions, HttpResponse, @@ -43,8 +44,6 @@ type JsonArgs< schema?: Schema; }; -type Task = () => Promise>; - // Copying will help to avoid circular structure // and mutation of the cached response. function copyResponse( @@ -207,7 +206,7 @@ export class Http { // istanbul ignore else: no cache tests if (!resPromise) { const startTime = Date.now(); - const httpTask: Task = () => { + const httpTask: GotTask = () => { const queueDuration = Date.now() - startTime; return gotTask(url, options, { method: options.method, @@ -217,12 +216,12 @@ export class Http { }; const throttle = this.getThrottle(url); - const throttledTask: Task = throttle + const throttledTask: GotTask = throttle ? () => throttle.add>(httpTask) : httpTask; const queue = getQueue(url); - const queuedTask: Task = queue + const queuedTask: GotTask = queue ? () => queue.add>(throttledTask) : throttledTask; diff --git a/lib/util/http/types.ts b/lib/util/http/types.ts index 42db468f1539f0..4f576ef17a1788 100644 --- a/lib/util/http/types.ts +++ b/lib/util/http/types.ts @@ -91,3 +91,5 @@ export interface HttpResponse { headers: HttpHeaders; authorization?: boolean; } + +export type GotTask = () => Promise>;