Skip to content

Commit eacab3b

Browse files
committed
docs: comment pubsub
License: MIT Signed-off-by: Henrique Dias <[email protected]>
1 parent cb50a15 commit eacab3b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pubsub.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,28 @@ func (s *subscription) close() {
5252
}
5353

5454
type pubsub struct {
55-
ctx context.Context
56-
cancel context.CancelFunc
55+
// ctx includes the context of the caller's context, wrapped
56+
// by cancelation through cancel.
57+
ctx context.Context
58+
cancel context.CancelFunc
59+
60+
// lastmod tracks the last time this pubsub instance was accessed
61+
// i.e., the last time something, or someone, subscribed or published.
5762
lastmod time.Time
58-
wg sync.WaitGroup
5963

60-
msgsMu sync.RWMutex
64+
// wg tracks if the worker for this pubsub instance is done or not.
65+
// The worker stops when the context is canceled.
66+
wg sync.WaitGroup
67+
68+
// msgs tracks all the messages published to this pubsub instance.
69+
// It is needed so when new subscriptions are created, we can send
70+
// all messages retroactively, in order.
6171
msgs []string
72+
msgsMu sync.RWMutex
6273

63-
subsMu sync.RWMutex
74+
// subs tracks the subscriptions for this pubsub instance.
6475
subs []*subscription
76+
subsMu sync.RWMutex
6577
}
6678

6779
func (ps *pubsub) subscribe(ctx context.Context) *subscription {

0 commit comments

Comments
 (0)