MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / DecrementInt16

Method DecrementInt16

pkg/util/cache/cache.go:683–700  ·  view source on GitHub ↗

Decrement an item of type int16 by n. Returns an error if the item's value is not an int16, or if it was not found. If there is no error, the decremented value is returned.

(k string, n int16)

Source from the content-addressed store, hash-verified

681// not an int16, or if it was not found. If there is no error, the decremented
682// value is returned.
683func (c *cache) DecrementInt16(k string, n int16) (int16, error) {
684 c.mu.Lock()
685 v, found := c.items[k]
686 if !found || v.Expired() {
687 c.mu.Unlock()
688 return 0, fmt.Errorf("Item %s not found", k)
689 }
690 rv, ok := v.Object.(int16)
691 if !ok {
692 c.mu.Unlock()
693 return 0, fmt.Errorf("The value for %s is not an int16", k)
694 }
695 nv := rv - n
696 v.Object = nv
697 c.items[k] = v
698 c.mu.Unlock()
699 return nv, nil
700}
701
702// Decrement an item of type int32 by n. Returns an error if the item's value is
703// not an int32, or if it was not found. If there is no error, the decremented

Callers 1

TestDecrementInt16Function · 0.80

Calls 3

LockMethod · 0.80
ExpiredMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestDecrementInt16Function · 0.64