service: add NopService and use for PexReactor (#8100)

This commit is contained in:
William Banfield
2022-03-09 14:33:57 -05:00
committed by GitHub
parent 6f7427ec7e
commit ddbc93d993
2 changed files with 12 additions and 1 deletions
+11
View File
@@ -14,6 +14,11 @@ var (
errAlreadyStopped = errors.New("already stopped")
)
var (
_ Service = (*BaseService)(nil)
_ Service = (*NopService)(nil)
)
// Service defines a service that can be started, stopped, and reset.
type Service interface {
// Start is called to start the service, which should run until
@@ -85,6 +90,12 @@ type BaseService struct {
impl Implementation
}
type NopService struct{}
func (NopService) Start(_ context.Context) error { return nil }
func (NopService) IsRunning() bool { return true }
func (NopService) Wait() {}
// NewBaseService creates a new BaseService.
func NewBaseService(logger log.Logger, name string, impl Implementation) *BaseService {
return &BaseService{
+1 -1
View File
@@ -357,7 +357,7 @@ func makeNode(
return nil, combineCloseError(err, makeCloser(closers))
}
var pexReactor service.Service
var pexReactor service.Service = service.NopService{}
if cfg.P2P.PexReactor {
pexReactor, err = pex.NewReactor(ctx, logger, peerManager, router.OpenChannel, peerManager.Subscribe(ctx))
if err != nil {