Skip to content

Commit

Permalink
Schedule next request to get data after previous request finishes (#1352
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jerelmiller committed May 6, 2024
1 parent 3aba499 commit 2761ff3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-tomatoes-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"apollo-client-devtools": patch
---

Schedule next request to get client data only after the previous one had finished.
17 changes: 10 additions & 7 deletions src/extension/devtools/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,23 @@ function startRequestInterval(ms = 500) {
let id: NodeJS.Timeout;

async function getClientData() {
if (panelWindow) {
panelWindow.send({
type: "update",
payload: await rpcClient.request("getClientOperations"),
});
try {
if (panelWindow) {
panelWindow.send({
type: "update",
payload: await rpcClient.request("getClientOperations"),
});
}
} finally {
id = setTimeout(getClientData, ms);
}
}

if (devtoolsMachine.state.value === "connected") {
getClientData();
id = setInterval(() => getClientData(), ms);
}

return () => clearInterval(id);
return () => clearTimeout(id);
}

const unsubscribers = new Set<() => void>();
Expand Down

0 comments on commit 2761ff3

Please sign in to comment.