MCPcopy
hub / github.com/lonng/nano / Multicast

Method Multicast

group.go:89–116  ·  view source on GitHub ↗

Multicast push the message to the filtered clients

(route string, v interface{}, filter SessionFilter)

Source from the content-addressed store, hash-verified

87
88// Multicast push the message to the filtered clients
89func (c *Group) Multicast(route string, v interface{}, filter SessionFilter) error {
90 if c.isClosed() {
91 return ErrClosedGroup
92 }
93
94 data, err := message.Serialize(v)
95 if err != nil {
96 return err
97 }
98
99 if env.Debug {
100 log.Println(fmt.Sprintf("Multicast %s, Data=%+v", route, v))
101 }
102
103 c.mu.RLock()
104 defer c.mu.RUnlock()
105
106 for _, s := range c.sessions {
107 if !filter(s) {
108 continue
109 }
110 if err = s.Push(route, data); err != nil {
111 log.Println(err.Error())
112 }
113 }
114
115 return nil
116}
117
118// Broadcast push the message(s) to all members
119func (c *Group) Broadcast(route string, v interface{}) error {

Callers

nothing calls this directly

Calls 4

isClosedMethod · 0.95
SerializeFunction · 0.92
PrintlnMethod · 0.80
PushMethod · 0.65

Tested by

no test coverage detected