Class: LaunchDarkly::Impl::MemoizedValue Private

Inherits:
Object
  • Object
show all
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.

Since:

  • 5.5.0

Instance Method Summary collapse

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.

Since:

  • 5.5.0



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

#getObject

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.

Since:

  • 5.5.0



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.

Since:

  • 5.5.0



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