信号 golang 中使用通道的简单信号量实现 用法 package main import ( "fmt" "math/rand" "time" "github.com/vada-ir/semaphore" ) func crawl ( index int , s semaphore. Semaphore ) { defer s . Release ( 1 ) fmt . Printf ( "crawling the site #%d \n " , index ) r := time . Duration ( rand . Intn ( 2 )) time . Sleep ( time . Second * r ) fmt . Printf ( "job #%d is done \n " , index ) } func main () { rand . Seed