Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions filter/cardano/cardano.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Cardano struct {
inputChan chan event.Event
outputChan chan event.Event
doneChan chan struct{}
wg sync.WaitGroup
stopOnce sync.Once
logger plugin.Logger
filterSet filterSet
Expand All @@ -51,12 +52,14 @@ func (c *Cardano) Start() error {
c.outputChan = make(chan event.Event, 10)
c.doneChan = make(chan struct{})
c.stopOnce = sync.Once{}
c.wg.Add(1)
go c.processEvents()
return nil
}

// processEvents handles incoming events and applies filters
func (c *Cardano) processEvents() {
defer c.wg.Done()
for {
select {
case <-c.doneChan:
Expand Down Expand Up @@ -287,6 +290,8 @@ func (c *Cardano) Stop() error {
if c.doneChan != nil {
close(c.doneChan)
}
// Wait for goroutine to exit before closing channels
c.wg.Wait()
if c.inputChan != nil {
close(c.inputChan)
}
Expand Down
13 changes: 5 additions & 8 deletions filter/cardano/cardano_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,13 @@ func TestCardano_Start(t *testing.T) {

func TestCardano_Stop(t *testing.T) {
c := New()
err := c.Stop()
err := c.Start()
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
// Check if channels are nil after stop
if c.inputChan != nil {
t.Fatalf("expected inputChan to be nil after stop")
t.Fatalf("expected no error on start, got %v", err)
}
if c.outputChan != nil {
t.Fatalf("expected outputChan to be nil after stop")
err = c.Stop()
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
}

Expand Down
Loading