mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-18 10:07:58 +00:00
refactor: clarify queue tracking names
This commit is contained in:
@@ -33,7 +33,7 @@ export const EventRoutes = () =>
|
||||
c.header("X-Content-Type-Options", "nosniff")
|
||||
return streamSSE(c, async (stream) => {
|
||||
const q = new AsyncQueue<string | null>({ name: "sse:event" })
|
||||
let done = false
|
||||
let closed = false
|
||||
|
||||
q.push(
|
||||
JSON.stringify({
|
||||
@@ -53,12 +53,12 @@ export const EventRoutes = () =>
|
||||
}, 10_000)
|
||||
|
||||
const stop = () => {
|
||||
if (done) return
|
||||
done = true
|
||||
if (closed) return
|
||||
closed = true
|
||||
clearInterval(heartbeat)
|
||||
unsub()
|
||||
q.push(null)
|
||||
q.done()
|
||||
q.untrack()
|
||||
log.info("event disconnected")
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const GlobalDisposedEvent = BusEvent.define("global.disposed", z.object({
|
||||
async function streamEvents(c: Context, name: string, subscribe: (q: AsyncQueue<string | null>) => () => void) {
|
||||
return streamSSE(c, async (stream) => {
|
||||
const q = new AsyncQueue<string | null>({ name })
|
||||
let done = false
|
||||
let closed = false
|
||||
|
||||
q.push(
|
||||
JSON.stringify({
|
||||
@@ -44,12 +44,12 @@ async function streamEvents(c: Context, name: string, subscribe: (q: AsyncQueue<
|
||||
}, 10_000)
|
||||
|
||||
const stop = () => {
|
||||
if (done) return
|
||||
done = true
|
||||
if (closed) return
|
||||
closed = true
|
||||
clearInterval(heartbeat)
|
||||
unsub()
|
||||
q.push(null)
|
||||
q.done()
|
||||
q.untrack()
|
||||
log.info("global event disconnected")
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ export class AsyncQueue<T> implements AsyncIterable<T> {
|
||||
})
|
||||
}
|
||||
|
||||
done() {
|
||||
untrack() {
|
||||
if (this.id === undefined) return
|
||||
all.delete(this.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user