class RSpecBackgroundProcess::ProcessPool::LRUPool
Public Class Methods
new(max_running, &lru_stop)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 168 def initialize(max_running, &lru_stop) @all = {} @max_running = max_running @running_keep = max_running > 0 ? LruHash.new(max_running) : VoidHash.new @running_all = Set[] @active = Set[] @after_store = [] @lru_stop = lru_stop end
Public Instance Methods
[](key)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 189 def [](key) if @all.member? key @active << key @running_keep[key] # bump on use if on running LRU list end @all[key] end
[]=(key, value)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 183 def []=(key, value) @active << key @all[key] = value @after_store.each{|callback| callback.call(key, value)} end
after_store(&callback)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 226 def after_store(&callback) @after_store << callback end
delete(key)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 197 def delete(key) @running_keep.delete(key) @running_all.delete(key) @active.delete(key) @all.delete(key) end
instances()
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 204 def instances @all.values end
not_running(key)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 221 def not_running(key) @running_keep.delete(key) @running_all.delete(key) end
reset_active()
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 208 def reset_active puts "WARNING: There are more active processes than max running allowed! Consider increasing max running from #{@max_running} to #{@active.length} or more." if @max_running < @active.length @active = Set.new trim! end
running(key)
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 214 def running(key) return unless @all.member? key @running_keep[key] = key @running_all << key trim! end
to_s()
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 179 def to_s "LRUPool[all: #{@all.length}, running: #{@running_all.length}, active: #{@active.map(&:to_s).join(',')}, keep: #{@running_keep.length}]" end
Private Instance Methods
to_stop()
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 238 def to_stop @running_all - @active - @running_keep.values end
trim!()
click to toggle source
# File lib/rspec-background-process/process_pool.rb, line 232 def trim! to_stop.each do |key| @lru_stop.call(key, @all[key]) end end