Sha256: 026329ec17becc3b39858ce800f2937a72c3a370a1e3e5589752ebdad01c1b6e
Contents?: true
Size: 645 Bytes
Versions: 15
Compression:
Stored size: 645 Bytes
Contents
require 'thread' # Mutex # A [LazySingleton] wraps the result of the provided block, # which is guaranteed to be called at-most-once, even if the # block's return value is nil. class ::LogStash::Util::LazySingleton def initialize(&block) @mutex = Mutex.new @block = block @instantiated = false end def instance unless @instantiated @mutex.synchronize do unless @instantiated @instance = @block.call @instantiated = true end end end return @instance end def reset! @mutex.synchronize do @instantiated = false @instance = nil end end end
Version data entries
15 entries across 15 versions & 1 rubygems