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 ) { const host = parseUrl ( url ) ?. host ; if ( ! host ) { return null ; } let queue = hostQueues . get ( host ) ; if ( queue === undefined ) { queue = null ; const concurrency = getRequestLimit ( url ) ; if ( concurrency ) { queue = new PQueue ( { concurrency } ) ; } } hostQueues . set ( host , queue ) ; return queue ; } export function clear ( ) { hostQueues . clear ( ) ; }