Class: Dry::Container::Item::Memoizable
- Inherits:
-
Dry::Container::Item
- Object
- Dry::Container::Item
- Dry::Container::Item::Memoizable
- Defined in:
- lib/dry/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::Container::Item
Instance Method Summary collapse
-
#call ⇒ Dry::Container::Item::Base
Returns the result of item call using a syncronized mutex.
-
#initialize(item, options = {}) ⇒ Dry::Container::Item::Base
constructor
Returns a new Memoizable instance.
Methods inherited from Dry::Container::Item
Constructor Details
#initialize(item, options = {}) ⇒ Dry::Container::Item::Base
Returns a new Memoizable instance
24 25 26 27 28 29 |
# File 'lib/dry/container/item/memoizable.rb', line 24 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.
14 15 16 |
# File 'lib/dry/container/item/memoizable.rb', line 14 def memoize_mutex @memoize_mutex end |
Instance Method Details
#call ⇒ Dry::Container::Item::Base
Returns the result of item call using a syncronized mutex
34 35 36 37 38 |
# File 'lib/dry/container/item/memoizable.rb', line 34 def call memoize_mutex.synchronize do @memoized_item ||= item.call end end |