Skip to content

Commit

Permalink
docs: comments on interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Oct 3, 2024
1 parent c319ff1 commit 54a7ed7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"github.com/antoniomika/syncmap"
)

/*
Broker receives published messages and dispatches the message to the
subscribing clients. An message contains a message topic that clients
subscribe to and brokers use these subscription lists for determining the
clients to receive the message.
*/
type Broker interface {
GetChannels() iter.Seq2[string, *Channel]
GetClients() iter.Seq2[string, *Client]
Expand Down
4 changes: 4 additions & 0 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func NewChannel(topic string) *Channel {
}
}

/*
Channel is a container for a topic. It holds the list of clients and
a data channel to receive a message.
*/
type Channel struct {
Topic string
Done chan struct{}
Expand Down
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func NewClient(ID string, rw io.ReadWriter, direction ChannelDirection, blockWri
}
}

/*
Client is the container for holding state between multiple devices. A
client has a direction (input, output, inputout) as well as a way to
send data to all the associated channels.
*/
type Client struct {
ID string
ReadWriter io.ReadWriter
Expand Down
11 changes: 11 additions & 0 deletions multicast.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/antoniomika/syncmap"
)

/*
Multicast is a flexible, bidirectional broker.
It provides the most pure version of our PubSub interface which lets
end-developers build one-to-many connections between publishers and
subscribers and vice versa.
It doesn't provide any topic filtering capabilities and is only
concerned with sending data to and from an `io.ReadWriter` via our
channels.
*/
type Multicast struct {
Broker
Logger *slog.Logger
Expand Down
7 changes: 7 additions & 0 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import (
"iter"
)

/*
PubSub is our take on a basic publisher and subscriber interface.
It has a few notable requirements:
- each operation must accept an array of channels
- some way to send, receive, and stream data between clients

Check failure on line 14 in pubsub.go

View workflow job for this annotation

GitHub Actions / test

Comment should end in a period (godot)
*/
type PubSub interface {
Broker
GetPubs() iter.Seq2[string, *Client]
Expand Down

0 comments on commit 54a7ed7

Please sign in to comment.