Sha256: 6e0b00fd80061bbd924bbcc04bb1bb30609a9fb2269a4a148ac93e6a28615be2
Contents?: true
Size: 1.16 KB
Versions: 45
Compression:
Stored size: 1.16 KB
Contents
require 'volt/utils/generic_pool' module Volt # 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. class GenericCountingPool < GenericPool # return a created item with a count def generate_new(*args) [0, create(*args)] end # Finds an item and tracks that it was checked out. Use # #remove when the item is no longer needed. def find(*args, &block) item = __lookup(*args, &block) item[0] += 1 item[1] end # Lookups an item def lookup(*args, &block) # Note: must call without args because of https://github.com/opal/opal/issues/500 item = super item[1] end def transform_item(item) [0, item] end 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 end end
Version data entries
45 entries across 45 versions & 1 rubygems