class SuperTailer::ExpireWhenIdle

Public Instance Methods

watch(timeout) { |line| ... } click to toggle source
# File lib/super_tailer/expire_when_idle.rb, line 5
def watch(timeout)
  watching = { enable: true }
  chrono = timer(timeout) { watching[:enable] = false }

  while watching[:enable] do
    tailer do |line|
      yield(line)
      chrono.reset
    end
  end
end

Private Instance Methods

timer(seconds, &blk) click to toggle source
# File lib/super_tailer/expire_when_idle.rb, line 18
def timer(seconds, &blk)
  timers = Timers::Group.new
  chrono = timers.after(seconds, &blk)
  Thread.new { timers.wait }
  chrono
end