Class: ZeevexThreadsafe::Synchronized
- Inherits:
-
ZeevexProxy::Base
- Object
- ZeevexProxy::Base
- ZeevexThreadsafe::Synchronized
- Defined in:
- lib/zeevex_threadsafe/synchronized.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(obj, mutex = Mutex.new) ⇒ Synchronized
constructor
A new instance of Synchronized.
- #method_missing(name, *args, &block) ⇒ Object
-
#synchronize(&block) ⇒ Object
Run a block within a synchronized block around this object’s mutex.
Constructor Details
#initialize(obj, mutex = Mutex.new) ⇒ Synchronized
Returns a new instance of Synchronized.
28 29 30 31 |
# File 'lib/zeevex_threadsafe/synchronized.rb', line 28 def initialize(obj, mutex = Mutex.new) super @__synchronized_mutex = mutex end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
33 34 35 36 37 |
# File 'lib/zeevex_threadsafe/synchronized.rb', line 33 def method_missing(name, *args, &block) @__synchronized_mutex.synchronize do super end end |
Class Method Details
.wrap(*args) ⇒ Object
48 49 50 |
# File 'lib/zeevex_threadsafe/synchronized.rb', line 48 def self.wrap(*args) Synchronized.new(*args) end |
Instance Method Details
#synchronize(&block) ⇒ Object
Run a block within a synchronized block around this object’s mutex
42 43 44 45 46 |
# File 'lib/zeevex_threadsafe/synchronized.rb', line 42 def synchronize(&block) @__synchronized_mutex.synchronize do yield end end |