Skip to content

Commit

Permalink
feat: allow passing the topic selector store to the transport
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Nov 6, 2024
1 parent 7d42cd1 commit 473d5f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 8 additions & 5 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,6 @@ func NewHub(options ...Option) (*Hub, error) {
opt.logger = l
}

if opt.transport == nil {
t, _ := DeprecatedNewLocalTransport(nil, nil)
opt.transport = t
}

if opt.topicSelectorStore == nil {
tss, err := NewTopicSelectorStoreLRU(DefaultTopicSelectorStoreLRUMaxEntriesPerShard, DefaultTopicSelectorStoreLRUShardCount)
if err != nil {
Expand All @@ -338,6 +333,14 @@ func NewHub(options ...Option) (*Hub, error) {
opt.topicSelectorStore = tss
}

if opt.transport == nil {
opt.transport = NewLocalTransport()
}

if ttss, ok := opt.transport.(TransportTopicSelectorStore); ok {
ttss.SetTopicSelectorStore(opt.topicSelectorStore)
}

if opt.metrics == nil {
opt.metrics = NopMetrics{}
}
Expand Down
7 changes: 6 additions & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ type Transport interface {
Close() error
}

// TransportSubscribers provide a method to retrieve the list of active subscribers.
// TransportSubscribers provides a method to retrieve the list of active subscribers.
type TransportSubscribers interface {
// GetSubscribers gets the last event ID and the list of active subscribers at this time.
GetSubscribers() (string, []*Subscriber, error)
}

// TransportTopicSelectorStore provides a method to pass the TopicSelectorStore to the transport.
type TransportTopicSelectorStore interface {
SetTopicSelectorStore(store *TopicSelectorStore)
}

// ErrClosedTransport is returned by the Transport's Dispatch and AddSubscriber methods after a call to Close.
var ErrClosedTransport = errors.New("hub: read/write on closed Transport")

Expand Down

0 comments on commit 473d5f4

Please sign in to comment.