This is a created article in which the information may have evolved or changed.
The ping is encapsulated as a co-function directly by the target IP concurrency
Go itself does not provide a way to wait for a join, it needs to implement its own
/* Simple coprocessor version */package mainimport ("ping" "FMT" "Time"//"OS" "StrConv") var fin chan string; Used to implement Jionall func Pingr (host string,timeout int) {t1:=time. Now (). Unixnano () alive,err:=ping. Ping (host,timeout)//alive,err:=true,0t2:=time. Now (). Unixnano () fmt. Println (Host,alive, (T2-T1)/1000000,err); Fin <-host}var iplist [253]stringfunc Main () {fin = make (Chan string) //array assignment for i: = 0; i < len (iplist); I + + {iplist[i]= "192.168.99." +strconv. Itoa (i+1) go Pingr (iplist[i],1000)} for I: = 0; I < Len (iplist); i++ { <-fin //fmt. PRINTLN (IP, "joined")}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.