Class: Steady::SyncronizedHash

Inherits:
Object
  • Object
show all
Defined in:
lib/steady.rb

Instance Method Summary collapse

Constructor Details

#initializeSyncronizedHash

Returns a new instance of SyncronizedHash.



8
9
10
11
# File 'lib/steady.rb', line 8

def initialize
  @hash = Hash.new
  @mutex = Mutex.new
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/steady.rb', line 13

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

#[]=(key) ⇒ Object



17
18
19
# File 'lib/steady.rb', line 17

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

#apply(changes) ⇒ Object



21
22
23
# File 'lib/steady.rb', line 21

def apply(changes)
  @mutex.synchronize { @hash.merge!(changes) }
end