Sha256: 9e0ec80b031d2bf22ceafebc04112ce2d270505339180db25673c70be462a4bc
Contents?: true
Size: 712 Bytes
Versions: 4
Compression:
Stored size: 712 Bytes
Contents
#Instances of this class proxies calls to a given-object by using a mutex or monitor. # #==== Examples # threadsafe_array = Tsafe::Proxy.new(:obj => []) # threadsafe_array << 5 # ret = threadsafe_array[0] # # threadsafe_array = Tsafe::Proxy.new(:obj => [], :monitor => true) class Tsafe::Proxy #Spawn needed vars. def initialize(args) if args[:monitor] @mutex = Monitor.new elsif args[:mutex] @mutex = args[:mutex] else @mutex = Mutex.new end @obj = args[:obj] end #Proxies all calls to this object through the mutex. def method_missing(method_name, *args, &block) @mutex.synchronize do @obj.__send__(method_name, *args, &block) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
tsafe-0.0.5 | lib/tsafe_proxy.rb |
tsafe-0.0.4 | include/proxy.rb |
tsafe-0.0.3 | include/proxy.rb |
tsafe-0.0.2 | include/proxy.rb |