Class: GraphQL::Execution::Lazy::LazyMethodMap::ConcurrentishMap Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/graphql/execution/lazy/lazy_method_map.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Mock the Concurrent::Map API

Instance Method Summary collapse

Constructor Details

#initializeConcurrentishMap

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConcurrentishMap



59
60
61
62
63
64
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 59

def initialize
  @semaphore = Mutex.new
  # Access to this hash must always be managed by the mutex
  # since it may be modified at runtime
  @storage = {}
end

Instance Method Details

#[]=(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
70
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 66

def []=(key, value)
  @semaphore.synchronize {
    @storage[key] = value
  }
end

#compute_if_absent(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
75
76
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 72

def compute_if_absent(key)
  @semaphore.synchronize {
    @storage.fetch(key) { @storage[key] = yield }
  }
end

#initialize_copy(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
81
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 78

def initialize_copy(other)
  @semaphore = Mutex.new
  @storage = other.copy_storage
end