Skip to content

Commit 28f31d1

Browse files
committed
Package doc
1 parent 2484b30 commit 28f31d1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

stream.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
/*
2+
Package eventsource is a library for dealing with server sent events in Go.
3+
4+
The library attempts to make as few assumptions as possible about how your apps
5+
will be written, and remains as generic as possible while still being simple and useful.
6+
7+
The three core obects to the library are Clients, Events, and Streams.
8+
9+
Client wraps an HTTP connection, and runs a worker routine to send events to the connected
10+
client in a thread-safe way. It gracefully handles client disconnects.
11+
12+
Event encapsulates all the data that can be sent with SSE, and contains the logic for converting
13+
it to wire format to send. Events are not thread-safe by themselves.
14+
15+
Stream is an abstraction for 0 or more Client connections, and adds some multiplexing and filtering
16+
on top of the Client. It also can act as an http.Handler to automatically register inbound client
17+
connections and disconnectinos.
18+
19+
A quick example of a simple sever that broadcasts a "tick" event every second
20+
21+
func main() {
22+
stream := &eventsource.Stream{}
23+
go func(s *eventsource.Stream) {
24+
for {
25+
time.Sleep(time.Second)
26+
stream.Broadcast(eventsource.DataEvent("tick"))
27+
}
28+
}(stream)
29+
http.ListenAndServe(":8080", stream)
30+
}
31+
32+
*/
133
package eventsource
234

335
import (

0 commit comments

Comments
 (0)