Class: Concurrent::Sequential::ThreadSequencer
- Inherits:
-
Object
- Object
- Concurrent::Sequential::ThreadSequencer
- Defined in:
- lib/concurrent/sequential/thread-sequencer.rb
Instance Method Summary collapse
-
#initialize ⇒ ThreadSequencer
constructor
A new instance of ThreadSequencer.
- #later(&block) ⇒ Object
- #shutdown(timeout = nil) ⇒ Object
Constructor Details
#initialize ⇒ ThreadSequencer
Returns a new instance of ThreadSequencer.
40 41 42 43 44 |
# File 'lib/concurrent/sequential/thread-sequencer.rb', line 40 def initialize @queue = Queue.new @shutdown = false @thread = Thread.new { run } end |
Instance Method Details
#later(&block) ⇒ Object
46 47 48 49 50 |
# File 'lib/concurrent/sequential/thread-sequencer.rb', line 46 def later(&block) raise ArgumentError, "No block given" unless block @queue << block self end |
#shutdown(timeout = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/concurrent/sequential/thread-sequencer.rb', line 52 def shutdown(timeout=nil) later { @shutdown = true } if @thread.alive? @thread.join(timeout) self end |