(msg *Message, timeout time.Duration)
| 209 | } |
| 210 | |
| 211 | func (q *queue) send(msg *Message, timeout time.Duration) (err error) { |
| 212 | if q.isClosed() { |
| 213 | return types.ErrChannelClosed |
| 214 | } |
| 215 | sub := q.chanSub(msg.Topic) |
| 216 | if sub.isClose == 1 { |
| 217 | return types.ErrChannelClosed |
| 218 | } |
| 219 | if timeout == -1 { |
| 220 | select { |
| 221 | case sub.high <- msg: |
| 222 | return nil |
| 223 | case <-sub.done: |
| 224 | return types.ErrChannelClosed |
| 225 | } |
| 226 | } |
| 227 | defer func() { |
| 228 | res := recover() |
| 229 | if res != nil { |
| 230 | err = res.(error) |
| 231 | } |
| 232 | }() |
| 233 | if timeout == 0 { |
| 234 | select { |
| 235 | case sub.high <- msg: |
| 236 | return nil |
| 237 | default: |
| 238 | qlog.Error("send chainfull", "msg", msg, "topic", msg.Topic, "sub", sub) |
| 239 | return ErrQueueChannelFull |
| 240 | } |
| 241 | } |
| 242 | t := time.NewTimer(timeout) |
| 243 | defer t.Stop() |
| 244 | select { |
| 245 | case sub.high <- msg: |
| 246 | case <-t.C: |
| 247 | qlog.Error("send timeout", "msg", msg, "topic", msg.Topic, "sub", sub) |
| 248 | return ErrQueueTimeout |
| 249 | } |
| 250 | return nil |
| 251 | } |
| 252 | |
| 253 | func (q *queue) sendAsyn(msg *Message) error { |
| 254 | if q.isClosed() { |
no test coverage detected