Let a bot answer its sessions side by side, and show a due reply in each
Replies were locked per bot, so a long reply in one session held up every other session's reply with nothing shown. The lock is now per session. A chat shows the thinking row whenever the user has the last word, rather than from the bot's face (one per user, shared by every session), so it shows even while the bot works elsewhere. A task waiting for its busy computer says so, and a job finishing while another still runs puts back the running one's face. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -65,4 +65,19 @@ describe("createKeyLock", () => {
|
||||
expect(failed).rejects.toThrow("boom");
|
||||
expect(await next).toBe("ok");
|
||||
});
|
||||
|
||||
test("is busy while a task with the key is running", async () => {
|
||||
const lock = createKeyLock();
|
||||
|
||||
expect(lock.busy({ key: 1 })).toBe(false);
|
||||
|
||||
const running = lock.run({ key: 1, task: () => wait(10) });
|
||||
|
||||
expect(lock.busy({ key: 1 })).toBe(true);
|
||||
expect(lock.busy({ key: 2 })).toBe(false);
|
||||
|
||||
await running;
|
||||
|
||||
expect(lock.busy({ key: 1 })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,5 +28,13 @@ export default function createKeyLock() {
|
||||
}
|
||||
}
|
||||
|
||||
return { run, size: () => tails.size };
|
||||
/**
|
||||
* Whether a task with this key is running or queued, so a caller can
|
||||
* say it's waiting before it joins the line.
|
||||
*/
|
||||
function busy({ key }: { key: string | number }) {
|
||||
return tails.has(String(key));
|
||||
}
|
||||
|
||||
return { run, busy, size: () => tails.size };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user