refactor: clarify queue tracking names
This commit is contained in:
parent
76b90e3fb1
commit
946d2eecbe
3 changed files with 9 additions and 9 deletions
|
|
@ -33,7 +33,7 @@ export const EventRoutes = () =>
|
||||||
c.header("X-Content-Type-Options", "nosniff")
|
c.header("X-Content-Type-Options", "nosniff")
|
||||||
return streamSSE(c, async (stream) => {
|
return streamSSE(c, async (stream) => {
|
||||||
const q = new AsyncQueue<string | null>({ name: "sse:event" })
|
const q = new AsyncQueue<string | null>({ name: "sse:event" })
|
||||||
let done = false
|
let closed = false
|
||||||
|
|
||||||
q.push(
|
q.push(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|
@ -53,12 +53,12 @@ export const EventRoutes = () =>
|
||||||
}, 10_000)
|
}, 10_000)
|
||||||
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
if (done) return
|
if (closed) return
|
||||||
done = true
|
closed = true
|
||||||
clearInterval(heartbeat)
|
clearInterval(heartbeat)
|
||||||
unsub()
|
unsub()
|
||||||
q.push(null)
|
q.push(null)
|
||||||
q.done()
|
q.untrack()
|
||||||
log.info("event disconnected")
|
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) {
|
async function streamEvents(c: Context, name: string, subscribe: (q: AsyncQueue<string | null>) => () => void) {
|
||||||
return streamSSE(c, async (stream) => {
|
return streamSSE(c, async (stream) => {
|
||||||
const q = new AsyncQueue<string | null>({ name })
|
const q = new AsyncQueue<string | null>({ name })
|
||||||
let done = false
|
let closed = false
|
||||||
|
|
||||||
q.push(
|
q.push(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|
@ -44,12 +44,12 @@ async function streamEvents(c: Context, name: string, subscribe: (q: AsyncQueue<
|
||||||
}, 10_000)
|
}, 10_000)
|
||||||
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
if (done) return
|
if (closed) return
|
||||||
done = true
|
closed = true
|
||||||
clearInterval(heartbeat)
|
clearInterval(heartbeat)
|
||||||
unsub()
|
unsub()
|
||||||
q.push(null)
|
q.push(null)
|
||||||
q.done()
|
q.untrack()
|
||||||
log.info("global event disconnected")
|
log.info("global event disconnected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ export class AsyncQueue<T> implements AsyncIterable<T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
done() {
|
untrack() {
|
||||||
if (this.id === undefined) return
|
if (this.id === undefined) return
|
||||||
all.delete(this.id)
|
all.delete(this.id)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue