Class: Concurrent::LazyRegister
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Synchronization::Object
|
Defined in: | lib/concurrent-ruby-edge/concurrent/lazy_register.rb |
Overview
**Edge Features** are under active development and may change frequently.
-
Deprecations are not added before incompatible changes.
-
Edge
version: major is always 0, minor bump means incompatible change, patch bump means compatible change. -
Edge
features may also lack tests and documentation. -
Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
Hash-like collection that store lazy evaluated values.
Class Attribute Summary
Synchronization::Object
- Inherited
Class Method Summary
- .new ⇒ LazyRegister constructor
Synchronization::Object
- Inherited
.atomic_attribute?, .atomic_attributes, | |
.attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
.attr_volatile | Creates methods for reading and writing (as |
.ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
.new | Has to be called by children. |
.safe_initialization!, .define_initialize_atomic_fields |
Synchronization::AbstractObject
- Inherited
Instance Method Summary
-
#[](key) ⇒ Object
Element reference.
-
#add(key, &block)
Alias for #register.
-
#delete(key)
Alias for #unregister.
-
#has_key?(key)
Alias for #registered?.
-
#key?(key)
Alias for #registered?.
-
#register(key) { ... } ⇒ LazyRegister
(also: #add, #store)
Element assignment.
-
#registered?(key) ⇒ true, false
(also: #key?, #has_key?)
Returns true if the given key is present.
-
#remove(key)
Alias for #unregister.
-
#store(key, &block)
Alias for #register.
-
#unregister(key) ⇒ LazyRegister
(also: #remove, #delete)
Un-registers the object under key, realized or not.
Synchronization::Object
- Inherited
Synchronization::Volatile
- Included
Synchronization::AbstractObject
- Inherited
Constructor Details
.new ⇒ LazyRegister
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 25
def initialize super self.data = {} end
Instance Method Details
#[](key) ⇒ Object
Element reference. Retrieves the value object corresponding to the key object. Returns nil if the key is not found. Raises an exception if the stored item raised an exception when the block was evaluated.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 38
def [](key) delay = data[key] delay ? delay.value! : nil end
#add(key, &block)
Alias for #register.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 67
alias_method :add, :register
#delete(key)
Alias for #unregister.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 81
alias_method :delete, :unregister
#has_key?(key)
Alias for #registered?.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 52
alias_method :has_key?, :registered?
#key?(key)
Alias for #registered?.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 51
alias_method :key?, :registered?
#register(key) { ... } ⇒ LazyRegister
Also known as: #add, #store
Element assignment. Associates the value given by value with the key given by key.
#registered?(key) ⇒ true
, false
Also known as: #key?, #has_key?
Returns true if the given key is present.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 47
def registered?(key) data.key?(key) end
#remove(key)
Alias for #unregister.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 80
alias_method :remove, :unregister
#store(key, &block)
Alias for #register.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 68
alias_method :store, :register
#unregister(key) ⇒ LazyRegister
Also known as: #remove, #delete
Un-registers the object under key, realized or not.
# File 'lib/concurrent-ruby-edge/concurrent/lazy_register.rb', line 75
def unregister(key) update_data { |h| h.dup.tap { |j| j.delete(key) } } self end