Dialer.Cancel is a new optional <-chan struct{} channel whose closure
indicates that the dial should be canceled. It is compatible with the
x/net/context and http.Request.Cancel types.
Tested by hand with:
package main
import (
"log"
"net"
"time"
)
func main() {
log.Printf("start.")
var d net.Dialer
cancel := make(chan struct{})
time.AfterFunc(2*time.Second, func() {
log.Printf("timeout firing")
close(cancel)
})
d.Cancel = cancel
c, err := d.Dial("tcp", "192.168.0.1:22")
if err != nil {
log.Print(err)
return
}
log.Fatalf("unexpected connect: %v", c)
}