File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -52,16 +52,28 @@ func (s *subscription) close() {
5252}
5353
5454type 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
6779func (ps * pubsub ) subscribe (ctx context.Context ) * subscription {
You can’t perform that action at this time.
0 commit comments