Skip to content

Commit

Permalink
Check for nil when stopping the fault tolerant consumer (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
adinhodovic authored Apr 9, 2021
1 parent 5daac3a commit 06b8f0b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions events/fault_tolerant_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package events

import (
"errors"
"github.com/avast/retry-go"
"log"
"sync"
"time"

"github.com/avast/retry-go"
)

var (
Expand All @@ -16,7 +17,7 @@ var (

type FaultTolerantConsumer struct {
config *CloudEventsConfig
hanlders []EventHandler
handlers []EventHandler
m sync.Mutex
delegate EventConsumer
isShuttingDown bool
Expand All @@ -37,7 +38,7 @@ func NewFaultTolerantCloudEventsConsumer(config *CloudEventsConfig) (*FaultToler
}

func (f *FaultTolerantConsumer) RegisterHandler(handler EventHandler) {
f.hanlders = append(f.hanlders, handler)
f.handlers = append(f.handlers, handler)
}

func (f *FaultTolerantConsumer) Start() error {
Expand Down Expand Up @@ -79,7 +80,7 @@ func (f *FaultTolerantConsumer) recreateConsumer() error {
}

f.delegate = delegate
for _, h := range f.hanlders {
for _, h := range f.handlers {
f.RegisterHandler(h)
}
return nil
Expand All @@ -89,6 +90,10 @@ func (f *FaultTolerantConsumer) Stop() error {
f.m.Lock()
defer f.m.Unlock()

if f.delegate == nil {
return nil
}

f.isShuttingDown = true
err := f.delegate.Stop()
return err
Expand Down

0 comments on commit 06b8f0b

Please sign in to comment.