renovate/lib/util/http/queue.ts
Sergei Zharinov f32871e496
refactor(util/http): Refresh queue implementation (#13417)
* refactor(util/http): Refresh queue implementation

* Use utils for url parsing
2022-01-07 12:44:55 +01:00

28 lines
670 B
TypeScript

import PQueue from 'p-queue';
import { parseUrl } from '../url';
import { getRequestLimit } from './host-rules';
const hostQueues = new Map<string | null, PQueue | null>();
export function getQueue(url: string): PQueue | null {
const host = parseUrl(url)?.host;
if (!host) {
return null;
}
let queue = hostQueues.get(host);
if (queue === undefined) {
queue = null; // null represents "no queue", as opposed to undefined
const concurrency = getRequestLimit(url);
if (concurrency) {
queue = new PQueue({ concurrency });
}
}
hostQueues.set(host, queue);
return queue;
}
export function clear(): void {
hostQueues.clear();
}