Advanced Go Concurrency Patterns

https://talks.golang.org/2013/advconc.slide#5

It's easy to go, but how to stop?

Long-lived programs need to clean up.

Let's look at how to write programs that handle communication, periodic events, and cancellation.

The core is Go's select statement: like a switch, but the decision is made based on the ability to communicate.

select {
case xc <- x:
    // sent x on xc
case y := <-yc:
    // received y from yc
}

 

posted @ 2019-12-25 19:15  papering  阅读(303)  评论(0编辑  收藏  举报