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.
- #shutdown(timeout = nil) ⇒ Object
- #soon(&block) ⇒ 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 @running = true @thread = Thread.new { run } end |
Instance Method Details
#shutdown(timeout = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/concurrent/sequential/thread-sequencer.rb', line 52 def shutdown(timeout=nil) soon { @running = false } if @thread.alive? @thread.join(timeout) self end |
#soon(&block) ⇒ Object
46 47 48 49 50 |
# File 'lib/concurrent/sequential/thread-sequencer.rb', line 46 def soon(&block) raise ArgumentError, "No block given" unless block @queue << block self end |