Class: AWS::Flow::Templates::ResultWorker::SynchronizedHash

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/templates/result.rb

Overview

Wrapper around a ruby Hash to provide synchronization around making changes to the encapsulated hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSynchronizedHash

Returns a new instance of SynchronizedHash.



16
17
18
19
# File 'lib/aws/templates/result.rb', line 16

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



21
22
23
24
25
# File 'lib/aws/templates/result.rb', line 21

def method_missing(method, *args)
  # Not very efficient but ruby structures are not thread
  # safe in MRI.
  @semaphore.synchronize{ return @hash.send(method, *args) }
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



14
15
16
# File 'lib/aws/templates/result.rb', line 14

def hash
  @hash
end