Load limiting safeguards
This commit is contained in:
parent
47f6971c56
commit
2484ed2815
22 changed files with 374 additions and 144 deletions
|
|
@ -3,21 +3,23 @@ title: Agent Inbox
|
|||
---
|
||||
|
||||
```js
|
||||
import {API, POLL} from "./components/config.js";
|
||||
import {API, apiFetch, pollDelay, sleep} from "./components/config.js";
|
||||
```
|
||||
|
||||
```js
|
||||
// Live poll: messages list
|
||||
const inboxState = (async function*() {
|
||||
let failures = 0;
|
||||
while (true) {
|
||||
let messages = [], ok = false;
|
||||
try {
|
||||
const resp = await fetch(`${API}/messages/?limit=100`);
|
||||
const resp = await apiFetch("/messages/?limit=100");
|
||||
ok = resp.ok;
|
||||
if (ok) messages = await resp.json();
|
||||
} catch {}
|
||||
failures = ok ? 0 : failures + 1;
|
||||
yield {messages, ok, ts: new Date()};
|
||||
await new Promise(res => setTimeout(res, POLL));
|
||||
await sleep(pollDelay({ok, failures}));
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue