Sha256: c1e2af4a9fbb0b29226998eac61eaeaea0d16ec3f978bedd68a3123cf8a6e6d9
Contents?: true
Size: 719 Bytes
Versions: 4
Compression:
Stored size: 719 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 #Spawns 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.11 | lib/tsafe_proxy.rb |
tsafe-0.0.10 | lib/tsafe_proxy.rb |
tsafe-0.0.9 | lib/tsafe_proxy.rb |
tsafe-0.0.6 | lib/tsafe_proxy.rb |