Skip to content

Commit

Permalink
chore: rename register routes to GetOrCreateChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 13, 2024
1 parent c62b44a commit 7cd0b00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions postq/pg/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ func (t *notifyRouter) WithRouteExtractor(routeExtractor routeExtractorFn) *noti
return t
}

// RegisterRoutes creates a single channel for the given routes and returns it.
func (t *notifyRouter) RegisterRoutes(routes ...string) <-chan string {
// If any of the routes already has a channel, we use that
// for all the routes.
// Caution: The caller needs to ensure that the route
// groups do not overlap.
// GetOrCreateChannel creates a single channel for the given routes.
//
// If any of the routes already has a channel, we use that existing for all the routes.
//
// Caution: The caller needs to ensure that the route
// groups do not overlap.
func (t *notifyRouter) GetOrCreateChannel(routes ...string) <-chan string {
pgNotifyChannel := make(chan string)
for _, we := range routes {
if existing, ok := t.registry[we]; ok {
Expand Down
4 changes: 2 additions & 2 deletions postq/pg/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestPGRouter(t *testing.T) {
}()

// Two subscribers
alpha := r.RegisterRoutes("alphaA", "alphaB")
beta := r.RegisterRoutes("beta")
alpha := r.GetOrCreateChannel("alphaA", "alphaB")
beta := r.GetOrCreateChannel("beta")

var alphaCount, betaCount int
timeout := time.NewTimer(time.Second * 3)
Expand Down

0 comments on commit 7cd0b00

Please sign in to comment.