Method: Concurrent::Map#fetch_or_store
- Defined in:
- lib/concurrent-ruby/concurrent/map.rb
#fetch_or_store(key, default_value = NULL) {|key| ... } ⇒ Object
Fetch value with key, or store default value when key is absent, or fail when no default_value is given. This is a two step operation, therefore not atomic. The store can overwrite other concurrently stored value.
205 206 207 208 209 |
# File 'lib/concurrent-ruby/concurrent/map.rb', line 205 def fetch_or_store(key, default_value = NULL) fetch(key) do put(key, block_given? ? yield(key) : (NULL == default_value ? raise_fetch_no_key : default_value)) end end |