Class: Uh::WM::Workers::MultiplexingWorker

Inherits:
BaseWorker
  • Object
show all
Defined in:
lib/uh/wm/workers/multiplexing_worker.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
4

Instance Method Summary collapse

Methods inherited from BaseWorker

#initialize

Constructor Details

This class inherits a constructor from Uh::WM::Workers::BaseWorker

Instance Method Details

#configure(timeout: DEFAULT_TIMEOUT, on_timeout: nil) ⇒ Object



7
8
9
10
# File 'lib/uh/wm/workers/multiplexing_worker.rb', line 7

def configure(timeout: DEFAULT_TIMEOUT, on_timeout: nil)
  @timeout    = timeout
  @on_timeout = on_timeout
end

#each_eventObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/uh/wm/workers/multiplexing_worker.rb', line 17

def each_event
  loop do
    @display.flush
    @logger.debug "select [#{@display_io.fileno}], _, _, #{@timeout}"
    rs, _ = IO.select [@display_io], [], [], @timeout
    @logger.debug " => #{rs.inspect}"
    if rs.nil? || rs.empty?
      @on_timeout.call if @on_timeout
    else
      yield @display.next_event while @display.pending?
    end
  end
end

#setupObject



12
13
14
15
# File 'lib/uh/wm/workers/multiplexing_worker.rb', line 12

def setup
  @display_io = IO.new(@display.fileno)
  self
end