Skip to content

Commit

Permalink
allow restart
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Sep 25, 2024
1 parent ac9b8cd commit 8df8873
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func NewListener(
listenerTimeout: 5 * blocktime,
metrics: metrics,
chainID: p.chainID,
closed: make(chan struct{}),
}, nil
}

Expand All @@ -99,6 +98,7 @@ func (cl *Listener) Start(context.Context) error {

ctx, cancel := context.WithCancel(context.Background())
cl.cancel = cancel
cl.closed = make(chan struct{})

sub, err := cl.fetcher.SubscribeNewBlockEvent(ctx)
if err != nil {
Expand All @@ -116,10 +116,10 @@ func (cl *Listener) Stop(ctx context.Context) error {
}

cl.cancel()
cl.cancel = nil

select {
case <-cl.closed:
cl.cancel = nil
cl.closed = nil
case <-ctx.Done():
return ctx.Err()
}
Expand Down

0 comments on commit 8df8873

Please sign in to comment.