Class: Concurrent::Sequential::ThreadSequencer

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent/sequential/thread-sequencer.rb

Instance Method Summary collapse

Constructor Details

#initializeThreadSequencer

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

Raises:

  • (ArgumentError)


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