7 // Manages resources with a limited number of concurrent slots for use for each key.
12 // Limits concurrent use of a resource. Push into the channel to use a slot, and receive to free
14 active map[Key]*activeValueType
17 type activeValueType struct {
22 type ActiveValueRef struct {
28 // Returns the limiting channel. Send to it to obtain a slot, and receive to release the slot.
29 func (me ActiveValueRef) C() chan struct{} {
33 // Drop the reference to a key, this allows keys to be reclaimed when they're no longer in use.
34 func (me ActiveValueRef) Drop() {
36 defer me.i.mu.Unlock()
39 delete(me.i.active, me.k)
43 // Get a reference to the values for a key. You should make sure to call Drop exactly once on the
44 // returned value when done.
45 func (i *Instance) GetRef(key Key) ActiveValueRef {
49 i.active = make(map[Key]*activeValueType)
51 v, ok := i.active[key]
54 ch: make(chan struct{}, i.SlotsPerKey),
59 return ActiveValueRef{