Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func (p *MyPubSub) Subscribe(subj string, cb MsgHandler) (Subscription, error) {
- p.mu.Lock()
- defer p.mu.Unlock()
- subscription := MySubscription{pubSub: p, subj: subj, cb: cb}
- p.subs[subj] = append(p.subs[subj], &subscription)
- if _, ok := p.conds[subj]; !ok {
- p.conds[subj] = sync.NewCond(&p.mu)
- }
- go func() {
- p.conds[subj].Wait()
- }()
- return &subscription, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement