youbbs
youbbs
1827 0 0

conc: 更优雅的使用并发

conc 是 go 中结构化并发的工具,使常见并发任务更容易、更安全。

conc

标准库:

func main() {
    var wg sync.WaitGroup
    for i := 0; i < 10; i++ {
        wg.Add(1)
        go func() {
            defer wg.Done()
            // crashes on panic!          
            doSomething()
        }()
    }
    wg.Wait()
}
func main() {
    var wg conc.WaitGroup
    for i := 0; i < 10; i++ {             
        wg.Go(doSomething)
    }
    wg.Wait()
}

https://github.com/sourcegraph/conc

0

See Also

Nearby


Discussion

Login Topics