go-waku/waku/v2/protocol/relay/subscription.go

30 lines
558 B
Go
Raw Normal View History

2021-11-01 10:42:55 -04:00
package relay
2021-04-14 22:17:12 -04:00
2023-05-05 15:19:15 +05:30
import "github.com/waku-org/go-waku/waku/v2/protocol"
2021-04-14 22:17:12 -04:00
type Subscription struct {
2023-05-05 15:19:15 +05:30
Unsubscribe func()
Ch <-chan *protocol.Envelope
2021-04-14 22:17:12 -04:00
}
2023-05-05 15:19:15 +05:30
func NoopSubscription() Subscription {
ch := make(chan *protocol.Envelope)
close(ch)
return Subscription{
Unsubscribe: func() {},
Ch: ch,
}
2021-04-14 22:17:12 -04:00
}
2023-05-05 15:19:15 +05:30
func ArraySubscription(msgs []*protocol.Envelope) Subscription {
ch := make(chan *protocol.Envelope, len(msgs))
2023-05-05 17:33:44 +05:30
for _, msg := range msgs {
ch <- msg
}
2023-05-05 15:19:15 +05:30
close(ch)
return Subscription{
Unsubscribe: func() {},
Ch: ch,
}
2021-04-14 22:17:12 -04:00
}