Class: DatWorkerPool::LockedObject
- Inherits:
-
Object
- Object
- DatWorkerPool::LockedObject
- Defined in:
- lib/dat-worker-pool/locked_object.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
-
#initialize(object = nil) ⇒ LockedObject
constructor
A new instance of LockedObject.
- #set(new_object) ⇒ Object
- #value ⇒ Object
- #with_lock(&block) ⇒ Object
Constructor Details
#initialize(object = nil) ⇒ LockedObject
Returns a new instance of LockedObject.
8 9 10 11 |
# File 'lib/dat-worker-pool/locked_object.rb', line 8 def initialize(object = nil) @object = object @mutex = Mutex.new end |
Instance Attribute Details
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
6 7 8 |
# File 'lib/dat-worker-pool/locked_object.rb', line 6 def mutex @mutex end |
Instance Method Details
#set(new_object) ⇒ Object
17 18 19 |
# File 'lib/dat-worker-pool/locked_object.rb', line 17 def set(new_object) @mutex.synchronize{ @object = new_object } end |
#value ⇒ Object
13 14 15 |
# File 'lib/dat-worker-pool/locked_object.rb', line 13 def value @mutex.synchronize{ @object } end |
#with_lock(&block) ⇒ Object
21 22 23 |
# File 'lib/dat-worker-pool/locked_object.rb', line 21 def with_lock(&block) @mutex.synchronize{ block.call(@mutex, @object) } end |