class Lmkplz::Encasement

Public Class Methods

define_settable_callback(name) click to toggle source
# File lib/lmkplz/encasement.rb, line 11
def self.define_settable_callback(name)
  define_method("on_#{name}") do |&block|
    @callback_mutex.synchronize { @callbacks[name] = block }
  end
end
new() click to toggle source
# File lib/lmkplz/encasement.rb, line 3
def initialize
  @callback_mutex = Mutex.new
  @add_paths_mutex = Mutex.new
  @add_paths_queue = []
  @gather_event_duration_ms = 200
  @callbacks = Hash.new { -> {} }
end

Public Instance Methods

active?() click to toggle source
# File lib/lmkplz/encasement.rb, line 64
def active?
  !!@kkttyl
end
add(dir) click to toggle source
# File lib/lmkplz/encasement.rb, line 41
def add(dir)
  if active?
    Metal.kkttyl_add(kkttyl, dir)
  else
    @add_paths_mutex.synchronize do
      @add_paths_queue.push(dir)
    end
  end
end
await() click to toggle source
# File lib/lmkplz/encasement.rb, line 51
def await
  if !active?
    raise "Call #malloc before #await"
  end

  callbacks =
    @callback_mutex.synchronize do
      @callbacks.values_at(:success, :failure, :timeout, :end)
    end

  Metal.kkttyl_await(kkttyl, 40, *callbacks)
end
free() click to toggle source
# File lib/lmkplz/encasement.rb, line 32
def free
  if !active?
    return
  end

  Metal.kkttyl_free(kkttyl)
  @kkttyl = nil
end
malloc() click to toggle source
# File lib/lmkplz/encasement.rb, line 22
def malloc
  kkttyl

  @add_paths_mutex.synchronize do
    while @add_paths_queue.any?
      add(@add_paths_queue.pop)
    end
  end
end

Private Instance Methods

kkttyl() click to toggle source
# File lib/lmkplz/encasement.rb, line 70
def kkttyl
  @kkttyl ||= Metal.kkttyl_new(@gather_event_duration_ms)
end