pubsub.go 597 B

1234567891011121314151617181920212223
  1. package internal
  2. import (
  3. "github.com/v2ray/v2ray-core/app"
  4. )
  5. type PubsubWithContext interface {
  6. Publish(context app.Context, topic string, message app.PubsubMessage)
  7. Subscribe(context app.Context, topic string, handler app.TopicHandler)
  8. }
  9. type contextedPubsub struct {
  10. context app.Context
  11. pubsub PubsubWithContext
  12. }
  13. func (this *contextedPubsub) Publish(topic string, message app.PubsubMessage) {
  14. this.pubsub.Publish(this.context, topic, message)
  15. }
  16. func (this *contextedPubsub) Subscribe(topic string, handler app.TopicHandler) {
  17. this.pubsub.Subscribe(this.context, topic, handler)
  18. }