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

Method newRequest

nats.go:4658–4683  ·  view source on GitHub ↗
(subj string, hdr, data []byte, timeout time.Duration)

Source from the content-addressed store, hash-verified

4656}
4657
4658func (nc *Conn) newRequest(subj string, hdr, data []byte, timeout time.Duration) (*Msg, error) {
4659 mch, token, err := nc.createNewRequestAndSend(subj, hdr, data)
4660 if err != nil {
4661 return nil, err
4662 }
4663
4664 t := globalTimerPool.Get(timeout)
4665 defer globalTimerPool.Put(t)
4666
4667 var ok bool
4668 var msg *Msg
4669
4670 select {
4671 case msg, ok = <-mch:
4672 if !ok {
4673 return nil, ErrConnectionClosed
4674 }
4675 case <-t.C:
4676 nc.mu.Lock()
4677 delete(nc.respMap, token)
4678 nc.mu.Unlock()
4679 return nil, ErrTimeout
4680 }
4681
4682 return msg, nil
4683}
4684
4685// oldRequest will create an Inbox and perform a Request() call
4686// with the Inbox reply and return the first reply received.

Callers 1

requestMethod · 0.95

Calls 3

GetMethod · 0.65
PutMethod · 0.65

Tested by

no test coverage detected