2021-11-22 14:48:32 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2022-11-09 19:53:01 +00:00
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol"
|
2023-05-05 09:49:15 +00:00
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
|
2021-11-22 14:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Adder func(msg *protocol.Envelope)
|
|
|
|
|
|
|
|
type runnerService struct {
|
2023-05-05 09:49:15 +00:00
|
|
|
broadcaster relay.Broadcaster
|
2023-10-20 19:56:18 +00:00
|
|
|
sub *relay.Subscription
|
2021-11-22 14:48:32 +00:00
|
|
|
adder Adder
|
|
|
|
}
|
|
|
|
|
2023-05-05 09:49:15 +00:00
|
|
|
func newRunnerService(broadcaster relay.Broadcaster, adder Adder) *runnerService {
|
2021-11-22 14:48:32 +00:00
|
|
|
return &runnerService{
|
|
|
|
broadcaster: broadcaster,
|
|
|
|
adder: adder,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *runnerService) Start() {
|
2023-10-20 19:56:18 +00:00
|
|
|
r.sub = r.broadcaster.RegisterForAll(relay.WithBufferSize(relay.DefaultRelaySubscriptionBufferSize))
|
2023-05-05 09:49:15 +00:00
|
|
|
for envelope := range r.sub.Ch {
|
|
|
|
r.adder(envelope)
|
2021-11-22 14:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *runnerService) Stop() {
|
2023-05-05 09:49:15 +00:00
|
|
|
r.sub.Unsubscribe()
|
2021-11-22 14:48:32 +00:00
|
|
|
}
|