_content/talks/2010/go_talk-20100121.html
package main
import "fmt"
func main() {
fmt.Printf("Hello, 世界\n")
}
func main() {
go expensiveComputation(x, y, z)
anotherExpensiveComputation(a, b, c)
}
for {
rw := l.Accept()
conn := newConn(rw, handler)
go conn.serve()
}
func computeAndSend(ch chan int, x, y, z int) {
ch <- expensiveComputation(x, y, z)
}
func main() {
ch := make(chan int)
go computeAndSend(ch, x, y, z)
v2 := anotherExpensiveComputation(a, b, c)
v1 := <-ch
fmt.Println(v1, v2)
}
func (client *Client) Call(method string, args, reply interface{}) os.Error {
// Send RPC message.
call := client.Go(method, args, reply, nil)
// Read reply from Done channel.
<-call.Done
return call.Error
}
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
func (client *Client) input() {
for {resp := client.readResponse()client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
func (client *Client) input() {
for {
resp := client.readResponse()client.mutex.Lock() c := client.pending[resp.Seq] client.pending[resp.Seq] = c, false client.mutex.Unlock()if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()if resp.Error != "" { c.Error = os.ErrorString(resp.error) } resp.Decode(c.Reply)c.Done <- c
}
}
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)c.Done \<- c}
}
func (client *Client) input() {
for {
resp := client.readResponse()
client.mutex.Lock()
c := client.pending[resp.Seq]
client.pending[resp.Seq] = c, false
client.mutex.Unlock()
if resp.Error != "" {
c.Error = os.ErrorString(resp.error)
}
resp.Decode(c.Reply)
c.Done <- c
}
}