H
Hono4d ago
Torsten

streamSSE onAbort never triggered

maybe I'm missing something obvious, but this never logs "disconnected" when I close the sse connection.
import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import { streamSSE } from 'hono/streaming'

const app = new Hono()
app.get('/test', (c) => {
c.header('Content-Type', 'text/event-stream')
c.header('Cache-Control', 'no-cache')
c.header('Connection', 'keep-alive')

return streamSSE(
c,
(stream) =>
new Promise((resolve) => {
console.log('connected')
stream.onAbort(() => {
console.log('disconnected')
})
}),
)
})

serve(
{
port: 4000,
hostname: '0.0.0.0',
fetch: app.fetch,
},
(info) => {
console.log(`Listening on port ${info.port}`)
},
)
import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import { streamSSE } from 'hono/streaming'

const app = new Hono()
app.get('/test', (c) => {
c.header('Content-Type', 'text/event-stream')
c.header('Cache-Control', 'no-cache')
c.header('Connection', 'keep-alive')

return streamSSE(
c,
(stream) =>
new Promise((resolve) => {
console.log('connected')
stream.onAbort(() => {
console.log('disconnected')
})
}),
)
})

serve(
{
port: 4000,
hostname: '0.0.0.0',
fetch: app.fetch,
},
(info) => {
console.log(`Listening on port ${info.port}`)
},
)
Whats wrong here?
1 Reply
ambergristle
ambergristle3d ago
the promise looks kind of funky normally you need to call resolve somewhere, no?

Did you find this page helpful?