Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Either] refactor: add either.Bytes alias #117

Merged
merged 1 commit into from
Oct 30, 2023
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
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]
)