class Volt::GenericCountingPool

A counting pool behaves like a normal GenericPool, except for each time lookup is called, remove should be called when complete. The item will be completely removed from the GenericCountingPool only when it has been removed an equal number of times it has been looked up.

Public Instance Methods

find(*args, &block) click to toggle source

Finds an item and tracks that it was checked out. Use remove when the item is no longer needed.

# File lib/volt/utils/generic_counting_pool.rb, line 17
def find(*args, &block)
  item = __lookup(*args, &block)

  item[0] += 1

  item[1]
end
generate_new(*args) click to toggle source

return a created item with a count

# File lib/volt/utils/generic_counting_pool.rb, line 11
def generate_new(*args)
  [0, create(*args)]
end
lookup(*args, &block) click to toggle source

Lookups an item

Calls superclass method
# File lib/volt/utils/generic_counting_pool.rb, line 26
def lookup(*args, &block)
  # Note: must call without args because of https://github.com/opal/opal/issues/500
  item = super

  item[1]
end
remove(*args) click to toggle source
Calls superclass method
# File lib/volt/utils/generic_counting_pool.rb, line 37
def remove(*args)
  item    = lookup_without_generate(*args)
  if item
    item[0] -= 1

    if item[0] == 0
      # Last one using this item has removed it.
      super(*args)
    end
  end
end
transform_item(item) click to toggle source
# File lib/volt/utils/generic_counting_pool.rb, line 33
def transform_item(item)
  [0, item]
end