rename MsgAndTags to Message

This commit is contained in:
Anton Kaliaev
2019-02-01 11:19:40 +04:00
parent 54cc5100f8
commit 61155f66a7
15 changed files with 95 additions and 110 deletions

View File

@ -25,8 +25,8 @@
//
// for {
// select {
// case msgAndTags <- subscription.Out():
// // handle msg and tags
// case msg <- subscription.Out():
// // handle msg.Data() and msg.Tags()
// case <-subscription.Cancelled():
// return subscription.Err()
// }
@ -170,7 +170,7 @@ func (s *Server) subscribe(ctx context.Context, clientID string, query Query, ou
}
subscription := &Subscription{
out: make(chan MsgAndTags, outCapacity),
out: make(chan Message, outCapacity),
cancelled: make(chan struct{}),
}
select {
@ -389,11 +389,11 @@ func (state *state) send(msg interface{}, tags TagMap) {
for clientID, subscription := range clientSubscriptions {
if cap(subscription.out) == 0 {
// block on unbuffered channel
subscription.out <- MsgAndTags{msg, tags}
subscription.out <- Message{msg, tags}
} else {
// don't block on buffered channels
select {
case subscription.out <- MsgAndTags{msg, tags}:
case subscription.out <- Message{msg, tags}:
default:
state.remove(clientID, qStr, ErrOutOfCapacity)
}

View File

@ -303,10 +303,10 @@ func benchmarkNClientsOneQuery(n int, b *testing.B) {
/// HELPERS
///////////////////////////////////////////////////////////////////////////////
func assertReceive(t *testing.T, expected interface{}, ch <-chan pubsub.MsgAndTags, msgAndArgs ...interface{}) {
func assertReceive(t *testing.T, expected interface{}, ch <-chan pubsub.Message, msgAndArgs ...interface{}) {
select {
case actual := <-ch:
assert.Equal(t, expected, actual.Msg(), msgAndArgs...)
assert.Equal(t, expected, actual.Data(), msgAndArgs...)
case <-time.After(1 * time.Second):
t.Errorf("Expected to receive %v from the channel, got nothing after 1s", expected)
debug.PrintStack()

View File

@ -20,7 +20,7 @@ var (
// 2) channel which is closed if a client is too slow or choose to unsubscribe
// 3) err indicating the reason for (2)
type Subscription struct {
out chan MsgAndTags
out chan Message
cancelled chan struct{}
mtx sync.RWMutex
@ -30,7 +30,7 @@ type Subscription struct {
// Out returns a channel onto which messages and tags are published.
// Unsubscribe/UnsubscribeAll does not close the channel to avoid clients from
// receiving a nil message.
func (s *Subscription) Out() <-chan MsgAndTags {
func (s *Subscription) Out() <-chan Message {
return s.out
}
@ -53,18 +53,18 @@ func (s *Subscription) Err() error {
return s.err
}
// MsgAndTags glues a message and tags together.
type MsgAndTags struct {
msg interface{}
// Message glues data and tags together.
type Message struct {
data interface{}
tags TagMap
}
// Msg returns a message.
func (mt MsgAndTags) Msg() interface{} {
return mt.msg
// Data returns an original data published.
func (msg Message) Data() interface{} {
return msg.data
}
// Tags returns tags.
func (mt MsgAndTags) Tags() TagMap {
return mt.tags
// Tags returns tags, which matched the client's query.
func (msg Message) Tags() TagMap {
return msg.tags
}