Sha256: 7d1af5e21c31a5902e2f25a6b95beb8434ec4a9855f6d1e1368179743ff6a73c

Contents?: true

Size: 748 Bytes

Versions: 16

Compression:

Stored size: 748 Bytes

Contents

require 'thread'

module Redwood

class IdleManager
  include Singleton

  IDLE_THRESHOLD = 60

  def initialize
    @no_activity_since = Time.now
    @idle = false
    @thread = nil
  end

  def ping
    if @idle
      UpdateManager.relay self, :unidle, Time.at(@no_activity_since)
      @idle = false
    end
    @no_activity_since = Time.now
  end

  def start
    @thread = Redwood::reporting_thread("checking for idleness") do
      while true
        sleep 1
        if !@idle and Time.now.to_i - @no_activity_since.to_i >= IDLE_THRESHOLD
          UpdateManager.relay self, :idle, Time.at(@no_activity_since)
          @idle = true
        end
      end
    end
  end

  def stop
    @thread.kill if @thread
    @thread = nil
  end
end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sup-0.16.0 lib/sup/idle.rb
sup-0.15.4 lib/sup/idle.rb
sup-0.15.3 lib/sup/idle.rb
sup-0.15.2 lib/sup/idle.rb
sup-0.15.1 lib/sup/idle.rb
sup-0.15.0 lib/sup/idle.rb
sup-0.14.1.1 lib/sup/idle.rb
sup-0.13.2.1 lib/sup/idle.rb
sup-0.14.1 lib/sup/idle.rb
sup-0.14.0 lib/sup/idle.rb
sup-0.13.2 lib/sup/idle.rb
sup-0.13.1 lib/sup/idle.rb
sup-0.13.0 lib/sup/idle.rb
sup-0.12.1 lib/sup/idle.rb
sup-0.12 lib/sup/idle.rb
sup-0.11 lib/sup/idle.rb