2021-11-01 14:42:55 +00:00
|
|
|
package relay
|
2021-04-15 02:17:12 +00:00
|
|
|
|
2023-05-05 09:49:15 +00:00
|
|
|
import "github.com/waku-org/go-waku/waku/v2/protocol"
|
2021-04-15 02:17:12 +00:00
|
|
|
|
2023-07-19 16:25:35 +00:00
|
|
|
// Subscription handles the details of a particular Topic subscription. There may be many subscriptions for a given topic.
|
2021-04-15 02:17:12 +00:00
|
|
|
type Subscription struct {
|
2023-05-05 09:49:15 +00:00
|
|
|
Unsubscribe func()
|
|
|
|
Ch <-chan *protocol.Envelope
|
2021-04-15 02:17:12 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 16:25:35 +00:00
|
|
|
// NoopSubscription creates a noop subscription that will not receive any envelope
|
2023-05-05 09:49:15 +00:00
|
|
|
func NoopSubscription() Subscription {
|
|
|
|
ch := make(chan *protocol.Envelope)
|
|
|
|
close(ch)
|
|
|
|
return Subscription{
|
|
|
|
Unsubscribe: func() {},
|
|
|
|
Ch: ch,
|
|
|
|
}
|
2021-04-15 02:17:12 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 16:25:35 +00:00
|
|
|
// ArraySubscription creates a subscription for a list of envelopes
|
2023-05-05 09:49:15 +00:00
|
|
|
func ArraySubscription(msgs []*protocol.Envelope) Subscription {
|
|
|
|
ch := make(chan *protocol.Envelope, len(msgs))
|
2023-05-05 12:03:44 +00:00
|
|
|
for _, msg := range msgs {
|
|
|
|
ch <- msg
|
|
|
|
}
|
2023-05-05 09:49:15 +00:00
|
|
|
close(ch)
|
|
|
|
return Subscription{
|
|
|
|
Unsubscribe: func() {},
|
|
|
|
Ch: ch,
|
|
|
|
}
|
2021-04-15 02:17:12 +00:00
|
|
|
}
|