第5章,部分字词修订。

This commit is contained in:
zhliner
2017-08-24 22:27:42 +08:00
parent 9c0723ff6a
commit ff3c5b0a70
11 changed files with 27 additions and 30 deletions

View File

@@ -103,11 +103,9 @@ func lookup(key string) int {
<u><i>gopl.io/ch5/trace</i></u>
```Go
func bigSlowOperation() {
defer trace("bigSlowOperation")() // don't forget the
extra parentheses
defer trace("bigSlowOperation")() // don't forget the extra parentheses
// ...lots of work…
time.Sleep(10 * time.Second) // simulate slow
operation by sleeping
time.Sleep(10 * time.Second) // simulate slow operation by sleeping
}
func trace(msg string) func() {
start := time.Now()
@@ -169,8 +167,7 @@ for _, filename := range filenames {
if err != nil {
return err
}
defer f.Close() // NOTE: risky; could run out of file
descriptors
defer f.Close() // NOTE: risky; could run out of file descriptors
// ...process f…
}
```