Skip to content

Commit

Permalink
Return custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoloch committed Oct 15, 2024
1 parent e2755fd commit 0860b49
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions blockchain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blockchain

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand All @@ -23,6 +24,10 @@ const (
EventsListeningTimeout = 60 * time.Second
)

var (
ErrHeaderChannelClosed = errors.New("header channel closed")
)

type EventsListener func(events []*parser.Event, blockNumber types.BlockNumber, blockHash types.Hash) error

type Client struct {
Expand Down Expand Up @@ -222,7 +227,7 @@ func forwardHeaders(ctx context.Context, from <-chan types.Header, to chan types
return ctx.Err()
case header, ok := <-from:
if !ok {
return context.Canceled
return ErrHeaderChannelClosed
}

select {
Expand All @@ -240,7 +245,7 @@ func getFirstLiveHeader(ctx context.Context, c <-chan types.Header) (types.Heade
return types.Header{}, ctx.Err()
case firstLiveHeader, ok := <-c:
if !ok {
return types.Header{}, context.Canceled
return types.Header{}, ErrHeaderChannelClosed
}

return firstLiveHeader, nil
Expand Down

0 comments on commit 0860b49

Please sign in to comment.