Class: Ruby::Rego::EnvironmentPool
- Inherits:
-
Object
- Object
- Ruby::Rego::EnvironmentPool
- Defined in:
- lib/ruby/rego/environment_pool.rb
Overview
Pools Environment instances for reuse across evaluations. Thread-safe for concurrent checkouts/checkins.
Instance Method Summary collapse
-
#checkin(environment) ⇒ void
-
#checkout(state) ⇒ Environment
-
#initialize(max_size: nil) ⇒ EnvironmentPool
constructor
:reek:ControlParameter.
Constructor Details
#initialize(max_size: nil) ⇒ EnvironmentPool
:reek:ControlParameter
12 13 14 15 16 17 |
# File 'lib/ruby/rego/environment_pool.rb', line 12 def initialize(max_size: nil) pool = [] # @type var pool: Array[Environment] @pool = pool @max_size = normalized_max_size(max_size) @mutex = Mutex.new end |
Instance Method Details
#checkin(environment) ⇒ void
This method returns an undefined value.
32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby/rego/environment_pool.rb', line 32 def checkin(environment) @mutex.synchronize do return nil if max_size_full?(@pool.length) environment.prepare_for_pool @pool << environment end nil end |
#checkout(state) ⇒ Environment
21 22 23 24 25 26 27 28 |
# File 'lib/ruby/rego/environment_pool.rb', line 21 def checkout(state) @mutex.synchronize do environment = @pool.pop # @type var environment: Environment? return Environment.from_state(state) unless environment environment.reset!(state) end end |