diff --git a/lib.js b/lib.js index e157292..a74baba 100644 --- a/lib.js +++ b/lib.js @@ -126,16 +126,14 @@ export async function fetchRss(source) { let waitingList = new Map() export const sleep = delay => new Promise(resolve => setTimeout(() => resolve(), delay) ) export const delayedFetch = async (url, options, courtesyWait = 5 * 1000) => { - let [ domain ] = /[\w-]+.[\w-]+$/.exec(url.hostname) - let timeout = waitingList.get(domain) ?? 0 - let now = Date.now() + let [ domain ] = /[\w-]+.[\w-]+$/.exec(new URL(url).hostname) + let waitFor = waitingList.get(domain) ?? 0 - if(timeout == null || timeout <= now) { - } else { - await sleep(timeout - now) + waitingList.set(domain, waitFor + courtesyWait) + if(waitFor !== 0) { + await sleep(waitFor) } - waitingList.set(domain, now + courtesyWait) return await fetch(url, options) }