MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / PubLoop

Method PubLoop

IceFireDB-PubSub/pkg/ppubsub/pubsubStore.go:188–218  ·  view source on GitHub ↗

A method of PubSub that publishes a chatmessage to the PubSub topic until the pubsub context closes

()

Source from the content-addressed store, hash-verified

186// A method of PubSub that publishes a chatmessage
187// to the PubSub topic until the pubsub context closes
188func (cr *PubSub) PubLoop() {
189 for {
190 select {
191 case <-cr.psctx.Done():
192 return
193
194 case message := <-cr.Outbound:
195 logrus.Infof("Outbound Message: %s", message)
196 // Create a ChatMessage
197 m := chatmessage{
198 Message: message,
199 SenderID: cr.selfid.String(),
200 SenderName: cr.ClientName,
201 }
202
203 // Marshal the ChatMessage into a JSON
204 messagebytes, err := json.Marshal(m)
205 if err != nil {
206 cr.Logs <- chatlog{logprefix: "puberr", logmsg: "could not marshal JSON"}
207 continue
208 }
209
210 // Publish the message to the topic
211 err = cr.pstopic.Publish(cr.psctx, messagebytes)
212 if err != nil {
213 cr.Logs <- chatlog{logprefix: "puberr", logmsg: "could not publish to topic"}
214 continue
215 }
216 }
217 }
218}
219
220// A method of PubSub that continuously reads from the subscription
221// until either the subscription or pubsub context closes.

Callers 1

JoinPubSubFunction · 0.95

Calls 2

DoneMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected