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

Method PubLoop

IceFireDB-SQLite/pkg/p2p/pubsub.go:125–154  ·  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

123// A method of PubSub that publishes a chatmessage
124// to the PubSub topic until the pubsub context closes
125func (cr *PubSub) PubLoop() {
126 for {
127 select {
128 case <-cr.psctx.Done():
129 return
130
131 case message := <-cr.Outbound:
132 // Create a ChatMessage
133 m := chatmessage{
134 Message: message,
135 SenderID: cr.selfid.String(),
136 SenderName: cr.ClientName,
137 }
138
139 // Marshal the ChatMessage into a JSON
140 messagebytes, err := json.Marshal(m)
141 if err != nil {
142 cr.Logs <- chatlog{logprefix: "puberr", logmsg: "could not marshal JSON"}
143 continue
144 }
145
146 // Publish the message to the topic
147 err = cr.pstopic.Publish(cr.psctx, messagebytes)
148 if err != nil {
149 cr.Logs <- chatlog{logprefix: "puberr", logmsg: "could not publish to topic"}
150 continue
151 }
152 }
153 }
154}
155
156// A method of PubSub that continuously reads from the subscription
157// 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