Skip to content

Commit 54a7ed7

Browse files
committed
docs: comments on interfaces
1 parent c319ff1 commit 54a7ed7

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

broker.go

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import (
1010
"github.com/antoniomika/syncmap"
1111
)
1212

13+
/*
14+
Broker receives published messages and dispatches the message to the
15+
subscribing clients. An message contains a message topic that clients
16+
subscribe to and brokers use these subscription lists for determining the
17+
clients to receive the message.
18+
*/
1319
type Broker interface {
1420
GetChannels() iter.Seq2[string, *Channel]
1521
GetClients() iter.Seq2[string, *Client]

channel.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func NewChannel(topic string) *Channel {
4646
}
4747
}
4848

49+
/*
50+
Channel is a container for a topic. It holds the list of clients and
51+
a data channel to receive a message.
52+
*/
4953
type Channel struct {
5054
Topic string
5155
Done chan struct{}

client.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func NewClient(ID string, rw io.ReadWriter, direction ChannelDirection, blockWri
2222
}
2323
}
2424

25+
/*
26+
Client is the container for holding state between multiple devices. A
27+
client has a direction (input, output, inputout) as well as a way to
28+
send data to all the associated channels.
29+
*/
2530
type Client struct {
2631
ID string
2732
ReadWriter io.ReadWriter

multicast.go

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import (
1010
"github.com/antoniomika/syncmap"
1111
)
1212

13+
/*
14+
Multicast is a flexible, bidirectional broker.
15+
16+
It provides the most pure version of our PubSub interface which lets
17+
end-developers build one-to-many connections between publishers and
18+
subscribers and vice versa.
19+
20+
It doesn't provide any topic filtering capabilities and is only
21+
concerned with sending data to and from an `io.ReadWriter` via our
22+
channels.
23+
*/
1324
type Multicast struct {
1425
Broker
1526
Logger *slog.Logger

pubsub.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
"iter"
77
)
88

9+
/*
10+
PubSub is our take on a basic publisher and subscriber interface.
11+
12+
It has a few notable requirements:
13+
- each operation must accept an array of channels
14+
- some way to send, receive, and stream data between clients
15+
*/
916
type PubSub interface {
1017
Broker
1118
GetPubs() iter.Seq2[string, *Client]

0 commit comments

Comments
 (0)