Go语言有一个select语句,可用于轮询多个通道并执行特定的操作,具体取决于哪个通道首先是非空的。 E.g. select {
case a := <- chanA:
foo(a)
case b := <- chanB:
baz(b)
case c := <- chanC:
bar(c)
}
这将等待,直到chanA,chanB或
下面的代码段已被写入ghci type GNum = TVar Int
-- updateNum will read a num and add the given value to it
updateNum :: GNum -> Int -> STM()
updateNum n v =
do t <- readTVar n
writeTVar n (v + t)
--