Update src/app/api/events/route.ts
Co-authored-by: qodo-free-for-open-source-projects[bot] <189517486+qodo-free-for-open-source-projects[bot]@users.noreply.github.com>
This commit is contained in:
parent
1ae7efb31b
commit
6fb9824c11
1 changed files with 18 additions and 9 deletions
|
|
@ -75,18 +75,27 @@ export async function GET(request: Request): Promise<Response> {
|
||||||
const lastTouchedPath = path.join(projectRoot, '.beads', 'last-touched');
|
const lastTouchedPath = path.join(projectRoot, '.beads', 'last-touched');
|
||||||
let lastTouchedVersion: number | null = null;
|
let lastTouchedVersion: number | null = null;
|
||||||
|
|
||||||
|
let isPolling = false;
|
||||||
const pollLastTouched = async () => {
|
const pollLastTouched = async () => {
|
||||||
const nextVersion = await readLastTouchedVersion(lastTouchedPath);
|
if (isPolling) {
|
||||||
if (nextVersion === null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lastTouchedVersion === null) {
|
isPolling = true;
|
||||||
lastTouchedVersion = nextVersion;
|
try {
|
||||||
return;
|
const nextVersion = await readLastTouchedVersion(lastTouchedPath);
|
||||||
}
|
if (nextVersion === null) {
|
||||||
if (nextVersion !== lastTouchedVersion) {
|
return;
|
||||||
lastTouchedVersion = nextVersion;
|
}
|
||||||
write(toSseFrame(issuesEventBus.emit(projectRoot, lastTouchedPath, 'changed')));
|
if (lastTouchedVersion === null) {
|
||||||
|
lastTouchedVersion = nextVersion;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (nextVersion !== lastTouchedVersion) {
|
||||||
|
lastTouchedVersion = nextVersion;
|
||||||
|
write(toSseFrame(issuesEventBus.emit(projectRoot, lastTouchedPath, 'changed')));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isPolling = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue