generated from coulomb/repo-seed
Load limiting safeguards
This commit is contained in:
@@ -3,24 +3,26 @@ title: Progress
|
||||
---
|
||||
|
||||
```js
|
||||
import {API, POLL} from "./components/config.js";
|
||||
import {POLL_HEAVY, apiFetch, pollDelay, sleep} from "./components/config.js";
|
||||
```
|
||||
|
||||
```js
|
||||
const progState = (async function*() {
|
||||
let failures = 0;
|
||||
while (true) {
|
||||
let data = [], tokenEvents = [], ok = false;
|
||||
try {
|
||||
const [r1, r2] = await Promise.all([
|
||||
fetch(`${API}/progress/?limit=500`),
|
||||
fetch(`${API}/token-events/?limit=1000`),
|
||||
apiFetch("/progress/?limit=500"),
|
||||
apiFetch("/token-events/?limit=1000"),
|
||||
]);
|
||||
ok = r1.ok;
|
||||
data = ok ? await r1.json() : [];
|
||||
tokenEvents = r2.ok ? await r2.json() : [];
|
||||
} catch {}
|
||||
failures = ok ? 0 : failures + 1;
|
||||
yield {data, tokenEvents, ok, ts: new Date()};
|
||||
await new Promise(res => setTimeout(res, POLL));
|
||||
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user