summaryrefslogtreecommitdiff
path: root/doc/progs/server1.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-12-16 10:29:53 +1100
committerRob Pike <r@golang.org>2009-12-16 10:29:53 +1100
commitaea97e0bd7da9cef1cc631ddbd3578a0877a4fcc (patch)
tree89f2452373bd20e8248aee25ea00a592177bca95 /doc/progs/server1.go
parent881d6064d23d9da5c7ff368bc7d41d271290deff (diff)
downloadgolang-aea97e0bd7da9cef1cc631ddbd3578a0877a4fcc.tar.gz
update tutorial.
R=rsc CC=golang-dev http://codereview.appspot.com/179063
Diffstat (limited to 'doc/progs/server1.go')
-rw-r--r--doc/progs/server1.go40
1 files changed, 20 insertions, 20 deletions
diff --git a/doc/progs/server1.go b/doc/progs/server1.go
index 591e27606..b8c09269b 100644
--- a/doc/progs/server1.go
+++ b/doc/progs/server1.go
@@ -7,50 +7,50 @@ package main
import "fmt"
type request struct {
- a, b int;
- replyc chan int;
+ a, b int
+ replyc chan int
}
type binOp func(a, b int) int
func run(op binOp, req *request) {
- reply := op(req.a, req.b);
- req.replyc <- reply;
+ reply := op(req.a, req.b)
+ req.replyc <- reply
}
func server(op binOp, service chan *request, quit chan bool) {
for {
select {
case req := <-service:
- go run(op, req); // don't wait for it
+ go run(op, req) // don't wait for it
case <-quit:
- return;
+ return
}
}
}
func startServer(op binOp) (service chan *request, quit chan bool) {
- service = make(chan *request);
- quit = make(chan bool);
- go server(op, service, quit);
- return service, quit;
+ service = make(chan *request)
+ quit = make(chan bool)
+ go server(op, service, quit)
+ return service, quit
}
func main() {
- adder, quit := startServer(func(a, b int) int { return a + b });
- const N = 100;
- var reqs [N]request;
+ adder, quit := startServer(func(a, b int) int { return a + b })
+ const N = 100
+ var reqs [N]request
for i := 0; i < N; i++ {
- req := &reqs[i];
- req.a = i;
- req.b = i + N;
- req.replyc = make(chan int);
- adder <- req;
+ req := &reqs[i]
+ req.a = i
+ req.b = i + N
+ req.replyc = make(chan int)
+ adder <- req
}
for i := N-1; i >= 0; i-- { // doesn't matter what order
if <-reqs[i].replyc != N + 2*i {
- fmt.Println("fail at", i);
+ fmt.Println("fail at", i)
}
}
- quit <- true;
+ quit <- true
}