From 044d5b7238741128629f63e8e25e333b7d971b2a Mon Sep 17 00:00:00 2001
From: Mark McGranaghan
package main
The state
will be a map as in the previous
-example.
var state = make(map[int]int)
-
Also as before we’ll count how many operations we -perform.
+As before we’ll count how many operations we perform.
Here is the goroutine that owns the state
. This
-goroutine repeatedly selects on the reads
and
-writes
channels, responding to requests as they
-arrive. A response is executed by first performing
-the requested operation and then sending a value
-on the response channel resp
to indicate success
-(and the desired value in the case of reads
).
Here is the goroutine that owns the state
, which
+is a map as in the previous example but now private
+to the stateful goroutine. This goroutine repeatedly
+selects on the reads
and writes
channels,
+responding to requests as they arrive. A response
+is executed by first performing the requested
+operation and then sending a value on the response
+channel resp
to indicate success (and the desired
+value in the case of reads
).
go func() {
- for {
+ var state = make(map[int]int)
+
for {
select {
case read := <-reads:
read.resp <- state[read.key]