MCPcopy
hub / github.com/grpc/grpc-go / Publish

Method Publish

internal/grpcsync/pubsub.go:99–115  ·  view source on GitHub ↗

Publish publishes the provided message to the PubSub, and invokes callbacks registered by subscribers asynchronously.

(msg any)

Source from the content-addressed store, hash-verified

97// Publish publishes the provided message to the PubSub, and invokes
98// callbacks registered by subscribers asynchronously.
99func (ps *PubSub) Publish(msg any) {
100 ps.mu.Lock()
101 defer ps.mu.Unlock()
102
103 ps.msg = msg
104 for sub := range ps.subscribers {
105 s := sub
106 ps.cs.TrySchedule(func(context.Context) {
107 ps.mu.Lock()
108 defer ps.mu.Unlock()
109 if !ps.subscribers[s] {
110 return
111 }
112 s.OnMessage(msg)
113 })
114 }
115}
116
117// Done returns a channel that is closed after the context passed to NewPubSub
118// is canceled and all updates have been sent to subscribers.

Calls 4

OnMessageMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
TryScheduleMethod · 0.45