Skip to content
Snippets Groups Projects
Unverified Commit 19e9e8ea authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(http): Extract `GotTask` type (#25713)

parent deeab520
No related branches found
No related tags found
No related merge requests found
......@@ -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<T> = () => Promise<HttpResponse<T>>;
// Copying will help to avoid circular structure
// and mutation of the cached response.
function copyResponse<T>(
......@@ -207,7 +206,7 @@ export class Http<Opts extends HttpOptions = HttpOptions> {
// istanbul ignore else: no cache tests
if (!resPromise) {
const startTime = Date.now();
const httpTask: Task<T> = () => {
const httpTask: GotTask<T> = () => {
const queueDuration = Date.now() - startTime;
return gotTask(url, options, {
method: options.method,
......@@ -217,12 +216,12 @@ export class Http<Opts extends HttpOptions = HttpOptions> {
};
const throttle = this.getThrottle(url);
const throttledTask: Task<T> = throttle
const throttledTask: GotTask<T> = throttle
? () => throttle.add<HttpResponse<T>>(httpTask)
: httpTask;
const queue = getQueue(url);
const queuedTask: Task<T> = queue
const queuedTask: GotTask<T> = queue
? () => queue.add<HttpResponse<T>>(throttledTask)
: throttledTask;
......
......@@ -91,3 +91,5 @@ export interface HttpResponse<T = string> {
headers: HttpHeaders;
authorization?: boolean;
}
export type GotTask<T> = () => Promise<HttpResponse<T>>;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment