Class: RSpec::Core::MemoizedHelpers::ThreadsafeMemoized

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/memoized_helpers.rb

Instance Method Summary collapse

Constructor Details

#initializeThreadsafeMemoized

Returns a new instance of ThreadsafeMemoized.



171
172
173
174
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/memoized_helpers.rb', line 171

def initialize
  @memoized = {}
  @mutex = Support::ReentrantMutex.new
end

Instance Method Details

#fetch_or_store(key) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/memoized_helpers.rb', line 176

def fetch_or_store(key)
  @memoized.fetch(key) do # only first access pays for synchronization
    @mutex.synchronize do
      @memoized.fetch(key) { @memoized[key] = yield }
    end
  end
end