examples/stream: Remove usage of Flusher
This commit is contained in:
parent
118e019df0
commit
c5b304216c
@ -38,9 +38,7 @@ func main() {
|
|||||||
defer wg.Wait()
|
defer wg.Wait()
|
||||||
mux.HandleFunc("/shutdown", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
|
mux.HandleFunc("/shutdown", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
|
||||||
fmt.Fprintln(w, "Shutting down...")
|
fmt.Fprintln(w, "Shutting down...")
|
||||||
if flusher, ok := w.(gemini.Flusher); ok {
|
w.Flush()
|
||||||
flusher.Flush()
|
|
||||||
}
|
|
||||||
go shutdownOnce.Do(func() {
|
go shutdownOnce.Do(func() {
|
||||||
server.Shutdown(context.Background())
|
server.Shutdown(context.Background())
|
||||||
wg.Done()
|
wg.Done()
|
||||||
@ -54,12 +52,6 @@ func main() {
|
|||||||
|
|
||||||
// stream writes an infinite stream to w.
|
// stream writes an infinite stream to w.
|
||||||
func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
|
func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
|
||||||
flusher, ok := w.(gemini.Flusher)
|
|
||||||
if !ok {
|
|
||||||
w.WriteHeader(gemini.StatusTemporaryFailure, "Internal error")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
@ -84,7 +76,7 @@ func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
fmt.Fprintln(w, s)
|
fmt.Fprintln(w, s)
|
||||||
if err := flusher.Flush(); err != nil {
|
if err := w.Flush(); err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user