Class: MultiMeasure::ThreadSafeHash
- Inherits:
-
Object
- Object
- MultiMeasure::ThreadSafeHash
- Includes:
- Enumerable
- Defined in:
- lib/multi_measure/thread_safe_hash.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ ThreadSafeHash
constructor
A new instance of ThreadSafeHash.
- #to_normal_hash ⇒ Object
Constructor Details
#initialize ⇒ ThreadSafeHash
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_hash ⇒ Object
22 23 24 |
# File 'lib/multi_measure/thread_safe_hash.rb', line 22 def to_normal_hash @mutex.synchronize { @hash.dup } end |