Skip to content

Commit

Permalink
docs: comment pubsub
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <[email protected]>
  • Loading branch information
hacdias committed Sep 24, 2021
1 parent cb50a15 commit eacab3b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,28 @@ func (s *subscription) close() {
}

type pubsub struct {
ctx context.Context
cancel context.CancelFunc
// ctx includes the context of the caller's context, wrapped
// by cancelation through cancel.
ctx context.Context
cancel context.CancelFunc

// lastmod tracks the last time this pubsub instance was accessed
// i.e., the last time something, or someone, subscribed or published.
lastmod time.Time
wg sync.WaitGroup

msgsMu sync.RWMutex
// wg tracks if the worker for this pubsub instance is done or not.
// The worker stops when the context is canceled.
wg sync.WaitGroup

// msgs tracks all the messages published to this pubsub instance.
// It is needed so when new subscriptions are created, we can send
// all messages retroactively, in order.
msgs []string
msgsMu sync.RWMutex

subsMu sync.RWMutex
// subs tracks the subscriptions for this pubsub instance.
subs []*subscription
subsMu sync.RWMutex
}

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

0 comments on commit eacab3b

Please sign in to comment.