class Uh::WM::Workers::KQueue

Constants

TIMEOUT_DEFAULT

Public Class Methods

new(timeout: TIMEOUT_DEFAULT) click to toggle source
Calls superclass method Uh::WM::Workers::Base::new
# File lib/uh/wm/workers/kqueue.rb, line 9
def initialize timeout: TIMEOUT_DEFAULT
  super
  @timeout = timeout * 1000
end

Public Instance Methods

work_events() click to toggle source
# File lib/uh/wm/workers/kqueue.rb, line 14
def work_events
  @before_watch.call if @before_watch
  queue.run
end

Private Instance Methods

queue() click to toggle source
# File lib/uh/wm/workers/kqueue.rb, line 21
def queue
  @queue ||= ::KQueue::Queue.new.tap do |q|
    @ios.each do |io|
      ::KQueue::Watcher.new(q, io.fileno, :read, [], nil, proc do |_|
        q.stop
        @on_read.call
      end)
    end
    ::KQueue::Watcher.new(q, 1, :timer, [], @timeout, proc do |_|
      q.stop
      @on_timeout.call
    end)
  end
end