Class: LaunchDarkly::Impl::MemoizedValue Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::MemoizedValue
- Defined in:
- lib/ldclient-rb/impl/memoized_value.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Simple implementation of a thread-safe memoized value whose generator function will never be run more than once, and whose value can be overridden by explicit assignment. Note that we no longer use this class and it will be removed in a future version.
Instance Method Summary collapse
- #get ⇒ Object private
-
#initialize(&generator) ⇒ MemoizedValue
constructor
private
A new instance of MemoizedValue.
- #set(value) ⇒ Object private
Constructor Details
#initialize(&generator) ⇒ MemoizedValue
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MemoizedValue.
8 9 10 11 12 13 |
# File 'lib/ldclient-rb/impl/memoized_value.rb', line 8 def initialize(&generator) @generator = generator @mutex = Mutex.new @inited = false @value = nil end |
Instance Method Details
#get ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 19 20 21 22 23 |
# File 'lib/ldclient-rb/impl/memoized_value.rb', line 15 def get @mutex.synchronize do unless @inited @value = @generator.call @inited = true end end @value end |
#set(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 |
# File 'lib/ldclient-rb/impl/memoized_value.rb', line 25 def set(value) @mutex.synchronize do @value = value @inited = true end end |