Dont even bother do allocate a channel
This commit is contained in:
parent
e2ca025569
commit
33e3a5396e
28
client.go
28
client.go
|
@ -44,26 +44,14 @@ type Client struct {
|
|||
}
|
||||
|
||||
// Do performs an asynchronous query. The msg *Msg is the question to ask, the
|
||||
// string addr is the address of the nameserver. The methods returns a channel
|
||||
// of *Exchange. If ch is nil, a new channel is allocated and returned. If ch
|
||||
// is non nil, ch is used and returned.
|
||||
func (c *Client) Do(msg *Msg, addr string, ch chan *Exchange) <-chan *Exchange {
|
||||
switch ch {
|
||||
case nil:
|
||||
ex := make(chan *Exchange)
|
||||
go func() {
|
||||
r, rtt, err := c.Exchange(msg, addr)
|
||||
ex <- &Exchange{msg, r, addr, rtt, err}
|
||||
}()
|
||||
return ex
|
||||
default:
|
||||
go func() {
|
||||
r, rtt, err := c.Exchange(msg, addr)
|
||||
ch <- &Exchange{msg, r, addr, rtt, err}
|
||||
}()
|
||||
return ch
|
||||
}
|
||||
panic("dns: not reached")
|
||||
// string addr is the address of the nameserver, ch is a channel of *Exchange.
|
||||
// This channel is used to send to the reply from the server to.
|
||||
func (c *Client) Do(msg *Msg, addr string, ch chan *Exchange) {
|
||||
go func() {
|
||||
r, rtt, err := c.Exchange(msg, addr)
|
||||
ch <- &Exchange{msg, r, addr, rtt, err}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
// Exchange performs an synchronous query. It sends the message m to the address
|
||||
|
|
Loading…
Reference in New Issue