Class: Celluloid::IO::Stream::Latch
- Inherits:
-
Object
- Object
- Celluloid::IO::Stream::Latch
- Defined in:
- lib/celluloid/io/stream.rb
Overview
Perform an operation exclusively, uncontested by other tasks
Instance Method Summary collapse
-
#initialize ⇒ Latch
constructor
A new instance of Latch.
-
#synchronize ⇒ Object
Synchronize an operation across all tasks in the current actor.
Constructor Details
#initialize ⇒ Latch
Returns a new instance of Latch.
370 371 372 373 374 |
# File 'lib/celluloid/io/stream.rb', line 370 def initialize @owner = nil @waiters = 0 @condition = Celluloid::Condition.new end |
Instance Method Details
#synchronize ⇒ Object
Synchronize an operation across all tasks in the current actor
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/celluloid/io/stream.rb', line 377 def synchronize actor = Thread.current[:celluloid_actor] return yield unless actor if @owner || @waiters > 0 @waiters += 1 @condition.wait @waiters -= 1 end @owner = Task.current begin ret = yield ensure @owner = nil @condition.signal if @waiters > 0 end ret end |