Skip to content

Instantly share code, notes, and snippets.

@glober-vaibhav
Created January 9, 2023 13:08
Show Gist options
  • Save glober-vaibhav/4a00b63231933f2ba3c4ef1c9ed96d05 to your computer and use it in GitHub Desktop.
Save glober-vaibhav/4a00b63231933f2ba3c4ef1c9ed96d05 to your computer and use it in GitHub Desktop.
// Subscribe subscribes to a topic
func (b *Agent) Subscribe(topic string) <-chan string {
b.mu.Lock()
defer b.mu.Unlock()
if b.closed {
return nil
}
ch := make(chan string)
b.subs[topic] = append(b.subs[topic], ch)
return ch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment