semaphore:golang 中使用通道的简单信号量实现

时间:2021-06-01 11:06:22
【文件属性】:
文件名称:semaphore:golang 中使用通道的简单信号量实现
文件大小:5KB
文件格式:ZIP
更新时间:2021-06-01 11:06:22
Go 信号 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
【文件预览】:
semaphore-master
----.gitignore(260B)
----semaphore_test.go(765B)
----semaphore.go(2KB)
----.travis.yml(425B)
----README.md(863B)
----resizable_semaphore.go(3KB)
----resizable_semaphore_test.go(1KB)
----example()
--------main.go(477B)

网友评论