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
|
|
|
|
|
|
|
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-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-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
|
|
|
}
|