class ProcVar
  extend Forwardable
  def_delegators :call, *instance_methods.reject {|x| x[/^__/]}

  def initialize &block
    @proc = block
  end

  def call
    @proc.call
  end

  def method_missing sym, *args, &block
    call.send sym, *args, &block
  end
end

class ProcUpdate < ProcVar
  def_delegator :@mut, :synchronize, :sync
  def initialize freq, &block
    @proc = block
    @freq = freq
    @mut = Mutex.new
    @update = Thread.new do
      begin
        while true
          tmp = @proc.call
          sync {@val = tmp}
          sleep @freq
        end
      rescue
      end
    end
  end

  def call
    sync {@val}
  end
end
