This is a creation in Article, where the information may have evolved or changed.
Refer to the Anyevent/coro version of the ping feature implementation.
Golang does not have a convenient pop/shift syntax, it can only be counted by its own array
/*gorouting version of the parallel ping */package mainimport ("ping" "FMT" "Time" "StrConv") var fin chan string; Used to implement Joinall//go no pop/shift operation, can only count var cur int/* define the process ping single target input: target ip/domain output: result, delay */func doit () {if cur >= len ( IPList) {Return}ip:=iplist[cur]cur++go Pingr (ip,1000)}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 <-hostdoit ()}//definition Iplistvar iplist [253]stringfunc Main () { // Create a queue fin = Make (Chan string) //array assignment for I: = 0; i < len (iplist); i++ {iplist[i]= "192.168.99." +strconv. Itoa (i+1) } //control concurrency cocurrent: = cur =0 for J: = 0; J < Cocurrent; J + + {doit ()} //Wait for end for I: = 0; I < Len (iplist); i++ { <-fin //fmt. PRINTLN (IP, "joined")}}