diff options
author | Rob Pike <r@golang.org> | 2009-01-15 17:54:07 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-01-15 17:54:07 -0800 |
commit | ec57a60bebcacf864189f04e538db6eed25e8286 (patch) | |
tree | 56d8004bbe6a6396df32bfa0b67a427365527356 /doc/progs/server1.go | |
parent | f4c0107ad4f6e67579347a0f99b8e9fa470f985a (diff) | |
download | golang-ec57a60bebcacf864189f04e538db6eed25e8286.tar.gz |
casify tutorial examples
will bring document in line in a later CL, which may include revisiting some of the names
R=rsc
DELTA=58 (0 added, 0 deleted, 58 changed)
OCL=22906
CL=22908
Diffstat (limited to 'doc/progs/server1.go')
-rw-r--r-- | doc/progs/server1.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/doc/progs/server1.go b/doc/progs/server1.go index b7e489d46..a547f6af0 100644 --- a/doc/progs/server1.go +++ b/doc/progs/server1.go @@ -4,40 +4,40 @@ package main -type Request struct { +type request struct { a, b int; replyc chan int; } -type BinOp (a, b int) int; +type binOp (a, b int) int; -func Run(op *BinOp, request *Request) { +func run(op *binOp, request *request) { result := op(request.a, request.b); request.replyc <- result; } -func Server(op *BinOp, service chan *Request, quit chan bool) { +func server(op *binOp, service chan *request, quit chan bool) { for { select { - case request := <-service: - go Run(op, request); // don't wait for it + case req := <-service: + go run(op, req); // don't wait for it case <-quit: return; } } } -func StartServer(op *BinOp) (service chan *Request, quit chan bool) { - service = make(chan *Request); +func startServer(op *binOp) (service chan *request, quit chan bool) { + service = make(chan *request); quit = make(chan bool); - go Server(op, service, quit); + go server(op, service, quit); return service, quit; } func main() { - adder, quit := StartServer(func(a, b int) int { return a + b }); + adder, quit := startServer(func(a, b int) int { return a + b }); const N = 100; - var reqs [N]Request; + var reqs [N]request; for i := 0; i < N; i++ { req := &reqs[i]; req.a = i; |