Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove subscriber #16

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type WorkspaceConfigCache struct {
configs *modelv2.WorkspaceConfigs
updateLock sync.Mutex
subscribers []*Subscriber
subscribers []chan notifications.WorkspaceConfigNotification
subscriberLock sync.Mutex
}

Expand Down Expand Up @@ -44,7 +44,7 @@ func (c *WorkspaceConfigCache) Set(configs *modelv2.WorkspaceConfigs) {
defer c.subscriberLock.Unlock()

for _, subscriber := range c.subscribers {
subscriber.notify(notifications.WorkspaceConfigNotification{})
subscriber <- notifications.WorkspaceConfigNotification{}
}
}

Expand Down Expand Up @@ -86,13 +86,12 @@ func (c *WorkspaceConfigCache) merge(configs *modelv2.WorkspaceConfigs) {
// Subscribers are notified in the order they are subscribed.
// They can monitor for updates by reading from the notifications channel, provided by the Notifications function.
// It is expected to handle any notifications in a timely manner, otherwise it will block the cache from updating.
func (c *WorkspaceConfigCache) Subscribe() *Subscriber {
func (c *WorkspaceConfigCache) Subscribe() chan notifications.WorkspaceConfigNotification {
c.subscriberLock.Lock()
defer c.subscriberLock.Unlock()

subscriber := &Subscriber{
notifications: make(chan notifications.WorkspaceConfigNotification),
}
subscriber := make(chan notifications.WorkspaceConfigNotification)

c.subscribers = append(c.subscribers, subscriber)

return subscriber
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCacheSubscriptions(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
for range s.Notifications() {
for range s {
configs = append(configs, c.Get())
wg.Done()
if len(configs) == 2 {
Expand Down
17 changes: 0 additions & 17 deletions internal/cache/subscriber.go

This file was deleted.

2 changes: 1 addition & 1 deletion sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ type Subscriber interface {
Notifications() chan notifications.WorkspaceConfigNotification
}

func (cp *ControlPlane) Subscribe() *cache.Subscriber {
func (cp *ControlPlane) Subscribe() chan notifications.WorkspaceConfigNotification {
return cp.configsCache.Subscribe()
}
Loading