Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created October 27, 2021 02:51
Show Gist options
  • Select an option

  • Save jayhuang75/24bbcd63de99b92c2f7da4ba6af882f8 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/24bbcd63de99b92c2f7da4ba6af882f8 to your computer and use it in GitHub Desktop.
go-train-delay-listen.go
func (l *Lister) ListenSubscription(cm chan<- *pubsub.Message, subID string) error {
defer l.pubsub.Close()
sub := l.pubsub.Subscription(subID)
// Receive blocks until the context is cancelled or an error occurs.
err := sub.Receive(l.ctx, func(ctx context.Context, msg *pubsub.Message) {
log.Debugf("[ListenSubscription] Receive message from pubsub:%q\n", string(msg.Data))
cm <- msg
})
if err != nil {
return fmt.Errorf("Receive: %v", err)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment