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

Method SubLoop

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

A method of PubSub that continuously reads from the subscription until either the subscription or pubsub context closes. The received message is parsed sent into the inbound channel

()

Source from the content-addressed store, hash-verified

221// until either the subscription or pubsub context closes.
222// The received message is parsed sent into the inbound channel
223func (cr *PubSub) SubLoop() {
224 // Start loop
225 for {
226 select {
227 case <-cr.psctx.Done():
228 return
229
230 default:
231 // Read a message from the subscription
232 message, err := cr.psub.Next(cr.psctx)
233 // Check error
234 if err != nil {
235 // Close the messages queue (subscription has closed)
236 close(cr.Inbound)
237 cr.Logs <- chatlog{logprefix: "suberr", logmsg: "subscription has closed"}
238 return
239 }
240
241 // Check if message is from self
242 //if message.ReceivedFrom == cr.selfid {
243 // continue
244 //}
245
246 // Declare a ChatMessage
247 cm := &chatmessage{}
248 // Unmarshal the message data into a ChatMessage
249 err = json.Unmarshal(message.Data, cm)
250 if err != nil {
251 cr.Logs <- chatlog{logprefix: "suberr", logmsg: "could not unmarshal JSON"}
252 continue
253 }
254
255 // Send the ChatMessage into the message queue
256 cr.Inbound <- *cm
257 logrus.Infof("Inbound Message: %s", cm.Message)
258 }
259 }
260}
261
262func (cr *PubSub) Writer() {
263 for {

Callers 1

JoinPubSubFunction · 0.95

Calls 2

DoneMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected