Class: GraphQL::Execution::Lazy::LazyMethodMap::ConcurrentishMap
- Inherits:
-
Object
- Object
- GraphQL::Execution::Lazy::LazyMethodMap::ConcurrentishMap
- Extended by:
- Forwardable
- Defined in:
- lib/graphql/execution/lazy/lazy_method_map.rb
Overview
Mock the Concurrent::Map API
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #compute_if_absent(key) ⇒ Object
-
#initialize ⇒ ConcurrentishMap
constructor
A new instance of ConcurrentishMap.
- #initialize_copy(other) ⇒ Object
Constructor Details
#initialize ⇒ ConcurrentishMap
Returns a new instance of ConcurrentishMap.
77 78 79 80 81 82 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 77 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
84 85 86 87 88 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 84 def []=(key, value) @semaphore.synchronize { @storage[key] = value } end |
#compute_if_absent(key) ⇒ Object
90 91 92 93 94 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 90 def compute_if_absent(key) @semaphore.synchronize { @storage.fetch(key) { @storage[key] = yield } } end |
#initialize_copy(other) ⇒ Object
96 97 98 99 |
# File 'lib/graphql/execution/lazy/lazy_method_map.rb', line 96 def initialize_copy(other) @semaphore = Mutex.new @storage = other.copy_storage end |