Open piotrpio opened 1 year ago
I'll try to work on this!
@wallyqs I'd suggest to refactor the functions in nats.go to be wrappers as in the following example:
func (nc *Conn) RequestMsg(msg *Msg, timeout time.Duration) (*Msg, error) {
if msg == nil {
return nil, ErrInvalidMsg
}
hdr, err := msg.headerBytes()
if err != nil {
return nil, err
}
return nc.request(msg.Subject, hdr, msg.Data, timeout)
}
should become:
func (nc *Conn) RequestMsg(msg *Msg, timeout time.Duration) (*Msg, error) {
ctx := context.Background()
timoutCtx,cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return nc.RequestMsgWithContext(timoutCtx, msg)
}
With the option to make the context.WithTimeOut a global variable. I'll continue to take a look at the code as I might get other ideas.
context.go
duplicates a lot of code fromnats.go
. Refactor those files to remove duplications and make the code DRY.