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

Inherits:
Object
  • Object
show all
Defined in:
aws-flow-ruby/aws-flow/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

- (SynchronizedHash) initialize

Returns a new instance of SynchronizedHash



16
17
18
19
# File 'aws-flow-ruby/aws-flow/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

- (Object) method_missing(method, *args)



21
22
23
24
25
# File 'aws-flow-ruby/aws-flow/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

- (Object) hash (readonly)

Returns the value of attribute hash



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

def hash
  @hash
end