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

Method getOrCreateStreamState

coderd/x/chatd/chatd.go:4706–4716  ·  view source on GitHub ↗

getOrCreateStreamState returns the per-chat stream state, creating one atomically if it doesn't exist. The returned state has its own mutex — callers must lock state.mu for access.

(chatID uuid.UUID)

Source from the content-addressed store, hash-verified

4704// state has its own mutex — callers must lock state.mu for
4705// access.
4706func (p *Server) getOrCreateStreamState(chatID uuid.UUID) *chatStreamState {
4707 if val, ok := p.chatStreams.Load(chatID); ok {
4708 state, _ := val.(*chatStreamState)
4709 return state
4710 }
4711 val, _ := p.chatStreams.LoadOrStore(chatID, &chatStreamState{
4712 subscribers: make(map[uuid.UUID]chan codersdk.ChatStreamEvent),
4713 })
4714 state, _ := val.(*chatStreamState)
4715 return state
4716}
4717
4718// cleanupStreamIfIdle removes the chat entry from the sync.Map when
4719// there are no subscribers, the stream is not buffering, and any

Calls 2

LoadOrStoreMethod · 0.80
LoadMethod · 0.45