This commit is contained in:
wjqserver 2025-09-10 02:40:41 +08:00
parent b4e073ae2f
commit 38ff5126e3

3
sse.go
View file

@ -6,7 +6,6 @@ package touka
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"net/http" "net/http"
"strings" "strings"
@ -66,6 +65,7 @@ func (e *Event) Render(w io.Writer) error {
// 这是推荐的、更简单安全的方式, 采用阻塞和回调的设计, 框架负责管理连接生命周期. // 这是推荐的、更简单安全的方式, 采用阻塞和回调的设计, 框架负责管理连接生命周期.
// //
// 详细用法: // 详细用法:
//
// r.GET("/sse/callback", func(c *touka.Context) { // r.GET("/sse/callback", func(c *touka.Context) {
// // streamer 回调函数会在一个循环中被调用. // // streamer 回调函数会在一个循环中被调用.
// c.EventStream(func(w io.Writer) bool { // c.EventStream(func(w io.Writer) bool {
@ -117,6 +117,7 @@ func (c *Context) EventStream(streamer func(w io.Writer) bool) {
// - 为防止 goroutine 泄漏, 建议发送方在 select 中同时监听 c.Request.Context().Done(). // - 为防止 goroutine 泄漏, 建议发送方在 select 中同时监听 c.Request.Context().Done().
// //
// 详细用法: // 详细用法:
//
// r.GET("/sse/channel", func(c *touka.Context) { // r.GET("/sse/channel", func(c *touka.Context) {
// eventChan, errChan := c.EventStreamChan() // eventChan, errChan := c.EventStreamChan()
// //