Skip to content

Commit

Permalink
feat: add maxExecutionTime for async-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Feb 4, 2024
1 parent 2bd298c commit bf820ad
Showing 1 changed file with 48 additions and 39 deletions.
87 changes: 48 additions & 39 deletions src/background/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,60 @@ const savedRSS: {
}
} = {}

const lock = new AsyncLock()
const lock = new AsyncLock({
maxExecutionTime: 3000,
})
export const getRSS = async (tabId, url) => {
await lock.acquire(tabId, async () => {
if (savedRSS[tabId]) {
setRSS(tabId, savedRSS[tabId])
return
}

report({
url,
})
const html = await sendToContentScript({
name: "requestHTML",
tabId,
})
if (!tabId || !url || !url.startsWith("http")) {
return
}
try {
await lock.acquire(tabId, async () => {
if (savedRSS[tabId]) {
setRSS(tabId, savedRSS[tabId])
return
}

if (chrome.offscreen) {
await setupOffscreenDocument("tabs/offscreen.html")
chrome.runtime.sendMessage({
target: "offscreen",
data: {
name: "requestRSSHub",
body: {
tabId,
html,
url,
rules: await storage.get("rules"),
},
},
})
} else {
const rsshub = sandboxGetRSSHub({
html,
report({
url,
rules: await storage.get("rules"),
})
setRSS(tabId, rsshub)
}
const html = await sendToContentScript({
name: "requestHTML",
tabId,
})

const pageRSS = await sendToContentScript({
name: "requestPageRSS",
tabId,
if (chrome.offscreen) {
await setupOffscreenDocument("tabs/offscreen.html")
chrome.runtime.sendMessage({
target: "offscreen",
data: {
name: "requestRSSHub",
body: {
tabId,
html,
url,
rules: await storage.get("rules"),
},
},
})
} else {
const rsshub = sandboxGetRSSHub({
html,
url,
rules: await storage.get("rules"),
})
setRSS(tabId, rsshub)
}

const pageRSS = await sendToContentScript({
name: "requestPageRSS",
tabId,
})
setRSS(tabId, pageRSS)
})
setRSS(tabId, pageRSS)
})
} catch (error) {
console.error(error)
}
}

export const getCachedRSS = (tabId) => {
Expand Down

0 comments on commit bf820ad

Please sign in to comment.