Skip to content

Commit

Permalink
allow nil listener
Browse files Browse the repository at this point in the history
  • Loading branch information
andyollylarkin committed Aug 25, 2023
1 parent 5706cb6 commit 05866be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *Subscriber) GetConnection() (Connection, error) {

// Connect establish connection.
func (s *Subscriber) Connect(l Listener) error {
if l == nil {
if l == nil && s.conn == nil {
return fmt.Errorf("listener cant be nil")
}

Expand Down
12 changes: 12 additions & 0 deletions subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ func TestSubscriberConnectionNotSetError(t *testing.T) {
}
}

func TestAllowNilListenerWhenConnectionSet(t *testing.T) {
pc := NewPipeConnection()
s, err := watermillnet.NewSubscriber(watermillnet.SubscriberConfig{
Marshaler: pkg.MessagePackMarshaler{},
Unmarshaler: pkg.MessagePackUnmarshaler{},
})
require.NoError(t, err)
s.SetConnection(pc)
err = s.Connect(nil)
require.NoError(t, err)
}

// Subscribe topic independent

// Susccribe receive multi message

0 comments on commit 05866be

Please sign in to comment.