Files
loki/scripts/test/run-polling.ts
Cato 2b0b1bc49a Unify mobile agent conversations, run status and shared project progress (#1201)
* Make mobile agent conversations and shared project progress coherent

* Remove the retired automatic personal-goal dispatch reader

* Keep the conversation connection indicator in sync with its live stream

* Preserve existing phone install identity and clarify the historical implementation plan

* Make session recovery instructions user-facing and record the security-alert source review

* Carry project proposals into coding handoffs and clarify empty-session routing
2026-10-14 22:58:37 -07:00

37 lines
1005 B
TypeScript

import assert from "node:assert/strict";
import { singleFlight } from "../../src/lib/single-flight";
async function main() {
let calls = 0;
let finish: (n: number) => void = () => {};
const load = singleFlight(() => {
calls++;
return new Promise<number>((r) => {
finish = r;
});
});
const first = load();
const again = load();
assert.equal(first, again);
await Promise.resolve();
assert.equal(calls, 1);
finish(42);
assert.equal(await first, 42);
const next = load();
await Promise.resolve();
assert.equal(calls, 2);
finish(43);
assert.equal(await next, 43);
let attempts = 0;
const retry = singleFlight(async () => {
if (!attempts++) throw Error("offline");
return "recovered";
});
await assert.rejects(retry(), /offline/);
assert.equal(await retry(), "recovered");
console.log("✓ slow refreshes share one request, settle normally and recover after failure");
}
main().catch((e) => {
console.error(e);
process.exitCode = 1;
});