Skip to content

Commit

Permalink
refactor: add either.Bytes alias (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite authored Oct 30, 2023
1 parent 2fb66bc commit fd0db1d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pkg/client/events_query/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type eventsQueryClient struct {
// corresponding connection which produces its inputs.
type eventsBytesAndConn struct {
// eventsBytes is an observable which is notified about chain event messages
// matching the given query. It receives an either.Either[[]byte] which is
// matching the given query. It receives an either.Bytes which is
// either an error or the event message bytes.
eventsBytes observable.Observable[either.Either[[]byte]]
eventsBytes observable.Observable[either.Bytes]
conn client.Connection
isClosed bool
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func NewEventsQueryClient(cometWebsocketURL string, opts ...client.EventsQueryCl
}

// EventsBytes returns an eventsBytes observable which is notified about chain
// event messages matching the given query. It receives an either.Either[[]byte]
// event messages matching the given query. It receives an either.Bytes
// which is either an error or the event message bytes.
// (see: https://pkg.go.dev/github.com/cometbft/cometbft/types#pkg-constants)
// (see: https://docs.cosmos.network/v0.47/core/events#subscribing-to-events)
Expand Down Expand Up @@ -151,7 +151,7 @@ func (eqc *eventsQueryClient) newEventsBytesAndConn(
}

// Construct an eventsBytes for the given query.
eventsBzObservable, eventsBzPublishCh := channel.NewObservable[either.Either[[]byte]]()
eventsBzObservable, eventsBzPublishCh := channel.NewObservable[either.Bytes]()

// Publish either events bytes or an error received from the connection to
// the eventsBz observable.
Expand Down Expand Up @@ -198,7 +198,7 @@ func (eqc *eventsQueryClient) openEventsBytesAndConn(
func (eqc *eventsQueryClient) goPublishEventsBz(
ctx context.Context,
conn client.Connection,
eventsBzPublishCh chan<- either.Either[[]byte],
eventsBzPublishCh chan<- either.Bytes,
) {
// Read and handle messages from the websocket. This loop will exit when the
// websocket connection is isClosed and/or returns an error.
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
// value which contains either an error or the event message bytes.
// TODO_HACK: The purpose of this type is to work around gomock's lack of
// support for generic types. For the same reason, this type cannot be an
// alias (i.e. EventsBytesObservable = observable.Observable[either.Either[[]byte]]).
type EventsBytesObservable observable.Observable[either.Either[[]byte]]
// alias (i.e. EventsBytesObservable = observable.Observable[either.Bytes]).
type EventsBytesObservable observable.Observable[either.Bytes]

// EventsQueryClient is used to subscribe to chain event messages matching the given query,
type EventsQueryClient interface {
Expand Down
5 changes: 4 additions & 1 deletion pkg/either/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package either
// AsyncError represents a value which could either be a synchronous error or
// an asynchronous error (sent through a channel). It wraps the more generic
// `Either` type specific for error channels.
type AsyncError Either[chan error]
type (
AsyncError Either[chan error]
Bytes = Either[[]byte]
)

0 comments on commit fd0db1d

Please sign in to comment.