MCPcopy Create free account
hub / github.com/33cn/chain33 / send

Method send

queue/queue.go:211–251  ·  view source on GitHub ↗
(msg *Message, timeout time.Duration)

Source from the content-addressed store, hash-verified

209}
210
211func (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
253func (q *queue) sendAsyn(msg *Message) error {
254 if q.isClosed() {

Callers 1

SendTimeoutMethod · 0.45

Calls 3

isClosedMethod · 0.95
chanSubMethod · 0.95
ErrorMethod · 0.65

Tested by

no test coverage detected