From bfda03465502d24fb79b50a7d6b90a1377e2aaf1 Mon Sep 17 00:00:00 2001 From: Marwan Sulaiman Date: Thu, 25 May 2023 10:04:16 -0400 Subject: [PATCH] Inline init as it's only called in one place --- portlist/poller.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/portlist/poller.go b/portlist/poller.go index 944560b7f..d7bea2777 100644 --- a/portlist/poller.go +++ b/portlist/poller.go @@ -104,13 +104,6 @@ func (p *Poller) setPrev(pl List) { // that it's been administratively disabled or the underlying // OS is not implemented. func (p *Poller) init() error { - p.initOnce.Do(func() { - p.initErr = p.initWithErr() - }) - return p.initErr -} - -func (p *Poller) initWithErr() error { if debugDisablePortlist() { return errors.New("portlist disabled by envknob") } @@ -169,11 +162,11 @@ func (p *Poller) send(ctx context.Context, pl List, plErr error) (sent bool) { // // Run may only be called once. func (p *Poller) Run(ctx context.Context) (chan Update, error) { - if p.os == nil { - err := p.init() - if err != nil { - return nil, fmt.Errorf("error initializing poller: %w", err) - } + p.initOnce.Do(func() { + p.initErr = p.init() + }) + if p.initErr != nil { + return nil, fmt.Errorf("error initializing poller: %w", p.initErr) } tick := time.NewTicker(p.Interval) defer tick.Stop()