Class: RSpecBackgroundProcess::ProcessPool::LRUPool
- Inherits:
-
Object
- Object
- RSpecBackgroundProcess::ProcessPool::LRUPool
- Defined in:
- lib/rspec-background-process/process_pool.rb
Defined Under Namespace
Classes: VoidHash
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #after_store(&callback) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(max_running, &lru_stop) ⇒ LRUPool
constructor
A new instance of LRUPool.
- #instances ⇒ Object
- #not_running(key) ⇒ Object
- #reset_active ⇒ Object
- #running(key) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(max_running, &lru_stop) ⇒ LRUPool
168 169 170 171 172 173 174 175 176 177 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
189 190 191 192 193 194 195 |
# 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) ⇒ Object
183 184 185 186 187 |
# 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) ⇒ Object
226 227 228 |
# File 'lib/rspec-background-process/process_pool.rb', line 226 def after_store(&callback) @after_store << callback end |
#delete(key) ⇒ Object
197 198 199 200 201 202 |
# 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 ⇒ Object
204 205 206 |
# File 'lib/rspec-background-process/process_pool.rb', line 204 def instances @all.values end |
#not_running(key) ⇒ Object
221 222 223 224 |
# 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 ⇒ Object
208 209 210 211 212 |
# 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) ⇒ Object
214 215 216 217 218 219 |
# 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 ⇒ Object
179 180 181 |
# 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 |