Sha256: 6ef7e9a57d73fc56dca55bf42a1886fac1dae73f7a57ef58fbf81c12b6ba17ba
Contents?: true
Size: 642 Bytes
Versions: 16
Compression:
Stored size: 642 Bytes
Contents
module LaunchDarkly # 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. class MemoizedValue def initialize(&generator) @generator = generator @mutex = Mutex.new @inited = false @value = nil end def get @mutex.synchronize do if !@inited @value = @generator.call @inited = true end end @value end def set(value) @mutex.synchronize do @value = value @inited = true end end end end
Version data entries
16 entries across 16 versions & 1 rubygems