MCPcopy Index your code
hub / github.com/coder/coder / Subscribe

Method Subscribe

agent/agentgit/pathstore.go:116–136  ·  view source on GitHub ↗

Subscribe returns a channel that receives a signal whenever paths change for chatID, along with an unsubscribe function that removes the channel.

(chatID uuid.UUID)

Source from the content-addressed store, hash-verified

114// paths change for chatID, along with an unsubscribe function
115// that removes the channel.
116func (ps *PathStore) Subscribe(chatID uuid.UUID) (<-chan struct{}, func()) {
117 ch := make(chan struct{}, 1)
118
119 ps.mu.Lock()
120 ps.subscribers[chatID] = append(ps.subscribers[chatID], ch)
121 ps.mu.Unlock()
122
123 unsub := func() {
124 ps.mu.Lock()
125 defer ps.mu.Unlock()
126 subs := ps.subscribers[chatID]
127 for i, s := range subs {
128 if s == ch {
129 ps.subscribers[chatID] = append(subs[:i], subs[i+1:]...)
130 break
131 }
132 }
133 }
134
135 return ch, unsub
136}

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45