Publish all values that arrive on the channel until it is closed or we encounter an error.
(c *EncodedConn, chVal reflect.Value, subject string)
| 37 | // Publish all values that arrive on the channel until it is closed or we |
| 38 | // encounter an error. |
| 39 | func 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 | // |
no test coverage detected