Class: Knj::Threadsafe::Proxy
Overview
Instances of this class proxies calls to a given-object by using a mutex or monitor.
Examples
threadsafe_array = Knj::Threadsafe::Proxy.new(:obj => []) threadsafe_array << 5 ret = threadsafe_array
threadsafe_array = Knj::Threadsafe::Proxy.new(:obj => [], :monitor => true)
Instance Method Summary collapse
-
#initialize(args) ⇒ Proxy
constructor
Spawn needed vars.
-
#method_missing(method_name, *args, &block) ⇒ Object
Proxies all calls to this object through the mutex.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Proxies all calls to this object through the mutex.
34 35 36 37 38 |
# File 'lib/knj/threadsafe.rb', line 34 def method_missing(method_name, *args, &block) @mutex.synchronize do @obj.__send__(method_name, *args, &block) end end |