Dont even bother do allocate a channel

This commit is contained in:
Miek Gieben 2012-11-19 16:55:14 +01:00
parent e2ca025569
commit 33e3a5396e
1 changed files with 8 additions and 20 deletions

View File

@ -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