// Set the value of a counter. func (coll *InMemoryMutexCollection) SetCounter(c *storage.MetaDataCounter) *storage.MetaDataCounter { coll.Lock() defer coll.Unlock() if ret, ok := coll.counters[c.Key]; ok { if ret.IsExpired() { ret.CreationDate = time.Now() } ret.Value = c.Value return ret } else { c.CreationDate = time.Now() coll.counters[c.Key] = c return c } }
// Set the value of a counter. func (coll *InMemoryCollection) SetCounter(c *storage.MetaDataCounter) *storage.MetaDataCounter { retChan := make(chan *storage.MetaDataCounter) defer close(retChan) coll.commands <- func() { if ret, ok := coll.counters[c.Key]; ok { if ret.IsExpired() { ret.CreationDate = time.Now() } ret.Value = c.Value retChan <- ret } else { c.CreationDate = time.Now() coll.counters[c.Key] = c retChan <- c } } var result = <-retChan return result }