From ddbc93d9934249b7c4f637a82bffc89edc7af620 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:33:57 -0500 Subject: [PATCH] service: add NopService and use for PexReactor (#8100) --- libs/service/service.go | 11 +++++++++++ node/node.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/service/service.go b/libs/service/service.go index f7701633a..6221c7d92 100644 --- a/libs/service/service.go +++ b/libs/service/service.go @@ -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{ diff --git a/node/node.go b/node/node.go index 4bb72f4f6..3329d9f9a 100644 --- a/node/node.go +++ b/node/node.go @@ -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 {