This commit is contained in:
Anton Kaliaev
2019-02-07 17:17:55 +04:00
parent 641182e5d3
commit 54cc5100f8
21 changed files with 170 additions and 212 deletions
+8 -4
View File
@@ -131,10 +131,14 @@ func (s *Server) BufferCapacity() int {
return s.cmdsCap
}
// Subscribe creates a subscription for the given client. An error will be
// returned to the caller if the context is canceled or if subscription already
// exist for pair clientID and query. outCapacity can be used to set a
// capacity for Subscription#Out channel (1 by default).
// Subscribe creates a subscription for the given client.
//
// An error will be returned to the caller if the context is canceled or if
// subscription already exist for pair clientID and query.
//
// outCapacity can be used to set a capacity for Subscription#Out channel (1 by
// default). Panics if outCapacity is less than or equal to zero. If you want
// an unbuffered channel, use SubscribeUnbuffered.
func (s *Server) Subscribe(ctx context.Context, clientID string, query Query, outCapacity ...int) (*Subscription, error) {
outCap := 1
if len(outCapacity) > 0 {
+1 -1
View File
@@ -306,7 +306,7 @@ func benchmarkNClientsOneQuery(n int, b *testing.B) {
func assertReceive(t *testing.T, expected interface{}, ch <-chan pubsub.MsgAndTags, msgAndArgs ...interface{}) {
select {
case actual := <-ch:
assert.Equal(t, expected, actual.Msg, msgAndArgs...)
assert.Equal(t, expected, actual.Msg(), msgAndArgs...)
case <-time.After(1 * time.Second):
t.Errorf("Expected to receive %v from the channel, got nothing after 1s", expected)
debug.PrintStack()
+12 -2
View File
@@ -55,6 +55,16 @@ func (s *Subscription) Err() error {
// MsgAndTags glues a message and tags together.
type MsgAndTags struct {
Msg interface{}
Tags TagMap
msg interface{}
tags TagMap
}
// Msg returns a message.
func (mt MsgAndTags) Msg() interface{} {
return mt.msg
}
// Tags returns tags.
func (mt MsgAndTags) Tags() TagMap {
return mt.tags
}