class RSpec::Core::MemoizedHelpers::ThreadsafeMemoized

@private

Public Class Methods

new() click to toggle source
# File lib/rspec/core/memoized_helpers.rb, line 171
def initialize
  @memoized = {}
  @mutex = Support::ReentrantMutex.new
end

Public Instance Methods

fetch_or_store(key) { || ... } click to toggle source
# File 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