Class: MultiMeasure::ThreadSafeHash

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/multi_measure/thread_safe_hash.rb

Instance Method Summary collapse

Constructor Details

#initializeThreadSafeHash

Returns a new instance of ThreadSafeHash.



3
4
5
6
# File 'lib/multi_measure/thread_safe_hash.rb', line 3

def initialize
  @mutex = Mutex.new
  @hash = {}
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
# File 'lib/multi_measure/thread_safe_hash.rb', line 8

def [](key)
  @mutex.synchronize { @hash[key] }
end

#[]=(key, value) ⇒ Object



12
13
14
# File 'lib/multi_measure/thread_safe_hash.rb', line 12

def []=(key, value)
  @mutex.synchronize { @hash[key] = value }
end

#each(&block) ⇒ Object



18
19
20
# File 'lib/multi_measure/thread_safe_hash.rb', line 18

def each(&block)
  @mutex.synchronize { @hash.each(&block) }
end

#to_normal_hashObject



22
23
24
# File 'lib/multi_measure/thread_safe_hash.rb', line 22

def to_normal_hash
  @mutex.synchronize { @hash.dup }
end