MCPcopy
hub / github.com/nats-io/nats.go / chPublish

Function chPublish

netchan.go:39–63  ·  view source on GitHub ↗

Publish all values that arrive on the channel until it is closed or we encounter an error.

(c *EncodedConn, chVal reflect.Value, subject string)

Source from the content-addressed store, hash-verified

37// Publish all values that arrive on the channel until it is closed or we
38// encounter an error.
39func chPublish(c *EncodedConn, chVal reflect.Value, subject string) {
40 for {
41 val, ok := chVal.Recv()
42 if !ok {
43 // Channel has most likely been closed.
44 return
45 }
46 if e := c.Publish(subject, val.Interface()); e != nil {
47 // Do this under lock.
48 c.Conn.mu.Lock()
49 defer c.Conn.mu.Unlock()
50
51 if c.Conn.Opts.AsyncErrorCB != nil {
52 // FIXME(dlc) - Not sure this is the right thing to do.
53 // FIXME(ivan) - If the connection is not yet closed, try to schedule the callback
54 if c.Conn.isClosed() {
55 go c.Conn.Opts.AsyncErrorCB(c.Conn, nil, e)
56 } else {
57 c.Conn.ach.push(func() { c.Conn.Opts.AsyncErrorCB(c.Conn, nil, e) })
58 }
59 }
60 return
61 }
62 }
63}
64
65// BindRecvChan binds a channel for receive operations from NATS.
66//

Callers 1

BindSendChanMethod · 0.85

Calls 3

isClosedMethod · 0.80
PublishMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected