streaming Helper
The streaming Helper provides a method to extend c.stream
.
Import
ts
import { Hono } from 'hono'
import { streamSSE } from 'hono/streaming'
import { Hono } from 'hono'
import { streamSSE } from 'hono/streaming'
ts
import { Hono } from 'https://deno.land/x/hono/mod.ts'
import { streamSSE } from 'https://deno.land/x/hono/helper.ts'
import { Hono } from 'https://deno.land/x/hono/mod.ts'
import { streamSSE } from 'https://deno.land/x/hono/helper.ts'
streamSSE()
It allows you to stream Server-Sent Events (SSE) seamlessly.
ts
const app = new Hono()
let id = 0
app.get('/sse', async (c) => {
return streamSSE(c, async (stream) => {
while (true) {
const message = `It is ${new Date().toISOString()}`
await stream.writeSSE({ data: message, event: 'time-update', id: String(id++) })
await stream.sleep(1000)
}
})
})
const app = new Hono()
let id = 0
app.get('/sse', async (c) => {
return streamSSE(c, async (stream) => {
while (true) {
const message = `It is ${new Date().toISOString()}`
await stream.writeSSE({ data: message, event: 'time-update', id: String(id++) })
await stream.sleep(1000)
}
})
})