Class: Dry::Core::Container::Item::Memoizable
- Inherits:
-
Dry::Core::Container::Item
- Object
- Dry::Core::Container::Item
- Dry::Core::Container::Item::Memoizable
- Defined in:
- lib/dry/core/container/item/memoizable.rb
Overview
Memoizable class to store and execute item calls
Instance Attribute Summary collapse
-
#memoize_mutex ⇒ Mutex
readonly
The stored mutex.
Attributes inherited from Dry::Core::Container::Item
Instance Method Summary collapse
-
#call ⇒ Dry::Core::Container::Item::Base
Returns the result of item call using a syncronized mutex.
-
#initialize(item, options = {}) ⇒ Dry::Core::Container::Item::Base
constructor
Returns a new Memoizable instance.
Methods inherited from Dry::Core::Container::Item
Constructor Details
#initialize(item, options = {}) ⇒ Dry::Core::Container::Item::Base
Returns a new Memoizable instance
23 24 25 26 27 28 |
# File 'lib/dry/core/container/item/memoizable.rb', line 23 def initialize(item, = {}) super raise_not_supported_error unless callable? @memoize_mutex = ::Mutex.new end |
Instance Attribute Details
#memoize_mutex ⇒ Mutex (readonly)
Returns the stored mutex.
13 14 15 |
# File 'lib/dry/core/container/item/memoizable.rb', line 13 def memoize_mutex @memoize_mutex end |
Instance Method Details
#call ⇒ Dry::Core::Container::Item::Base
Returns the result of item call using a syncronized mutex
33 34 35 36 37 |
# File 'lib/dry/core/container/item/memoizable.rb', line 33 def call memoize_mutex.synchronize do @memoized_item ||= item.call end end |