Merge branch 'master' of github.com:gopl-zh/gopl-zh.github.com

This commit is contained in:
Xargin 2016-07-24 22:43:42 +08:00
commit da5d8dda79

View File

@ -163,7 +163,8 @@ type Memo struct {
// Get is concurrency-safe. // Get is concurrency-safe.
func (memo *Memo) Get(key string) (value interface{}, err error) { func (memo *Memo) Get(key string) (value interface{}, err error) {
res, ok := memo.cache[key] if!ok{ res, ok := memo.cache[key]
if !ok {
res.value, res.err = memo.f(key) res.value, res.err = memo.f(key)
memo.cache[key] = res memo.cache[key] = res
memo.mu.Lock() memo.mu.Lock()