Sha256: 3e919a6fcb995080ea5f1ab9895472a7d4130e0cec36cb15f271bfa05b5642e6

Contents?: true

Size: 605 Bytes

Versions: 7

Compression:

Stored size: 605 Bytes

Contents

require "clearsight/version"
require "clearsight/deploy"
require 'thread'

module Clearsight
  class Timer
    def initialize(interval, &handler)
      @run = true
      @semaphore = Mutex.new

      @th = Thread.new do
        t = Time.now
        while run?
          t += interval
          (sleep(t - Time.now) rescue nil) and handler.call rescue nil
        end
      end
    end

    def stop
      @semaphore.synchronize do
        @run = false
      end
      @th.join
    end

    private

    def run?
      @semaphore.synchronize do
        @run
      end
    end
  end
end
::CS = ::Clearsight

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
clearsight-0.0.12 lib/clearsight.rb
clearsight-0.0.11 lib/clearsight.rb
clearsight-0.0.10 lib/clearsight.rb
clearsight-0.0.9 lib/clearsight.rb
clearsight-0.0.8 lib/clearsight.rb
clearsight-0.0.7 lib/clearsight.rb
clearsight-0.0.6 lib/clearsight.rb