go-waku/cmd/waku/server/rpc/runner.go

33 lines
638 B
Go
Raw Normal View History

2021-11-22 14:48:32 +00:00
package rpc
import (
"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
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-05-05 12:03:44 +00:00
r.sub = r.broadcaster.RegisterForAll(1024)
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
}