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

Function JoinPubSub

IceFireDB-SQLProxy/pkg/p2p/pubsub.go:36–59  ·  view source on GitHub ↗

JoinPubSub joins a pubsub topic and sets up message handling

(p2p *P2P, name string, topicName string)

Source from the content-addressed store, hash-verified

34
35// JoinPubSub joins a pubsub topic and sets up message handling
36func JoinPubSub(p2p *P2P, name string, topicName string) (*PubSub, error) {
37 topic, err := p2p.PubSub.Join(topicName)
38 if err != nil {
39 return nil, err
40 }
41
42 sub, err := topic.Subscribe()
43 if err != nil {
44 return nil, err
45 }
46
47 ps := &PubSub{
48 PubSub: p2p.PubSub,
49 Topic: topic,
50 Sub: sub,
51 Inbound: make(chan *Message),
52 Outbound: make(chan string),
53 }
54
55 go ps.handleInbound(p2p.Ctx)
56 go ps.handleOutbound(p2p.Ctx)
57
58 return ps, nil
59}
60
61func (ps *PubSub) handleInbound(ctx context.Context) {
62 for {

Callers 1

initP2PFunction · 0.92

Calls 2

handleInboundMethod · 0.95
handleOutboundMethod · 0.95

Tested by

no test coverage detected