class Viewing::ViewProxy

ViewProxy class threading proxy

Public Class Methods

new(obj) click to toggle source

initialization

@param obj [Object] Target object

# File lib/view_proxy.rb, line 18
def initialize(obj)
  @obj = obj
  @tg = ThreadGroup.new
  @upd_mon = Monitor.new
  @update = @upd_mon.new_cond
end

Public Instance Methods

close() click to toggle source

close call

# File lib/view_proxy.rb, line 64
def close
  @obj.close if @obj.respond_to?('close')
  @thread.raise(StopError, 'stop')
  @thread.join
end
store(key,values,options) click to toggle source

thread-safe store call

@param key [String] Value in first cell of data row @param values [Array] Values in cells of row @param options [Hash] Options: color styles

# File lib/view_proxy.rb, line 30
def store(key,values,options)
  @upd_mon.synchronize {
    @obj.store(key,values,options) if @obj.respond_to?('store')
    @update.signal
  }
end
update(name=nil) click to toggle source

update loop

@param name [String] name of viewing thread

# File lib/view_proxy.rb, line 40
def update(name=nil)
  @thread = Thread.new {
    Thread.current[:name] = (name || "thread #{Thread.current.object_id}")
    loop {
      begin
        @upd_mon.synchronize {
          @update.wait(1)
          Thread.handle_interrupt(RuntimeError => :on_blocking) {
            @obj.update if @obj.respond_to?('update')
            Thread.handle_interrupt(StopError => :immediate) {} if Thread.pending_interrupt?
          }
        }
        Thread.pass
      rescue StopError
        puts "#{Thread.current[:name]}\n  #{Thread.current.inspect}"
        Thread.current.exit
      rescue
        sleep(1)
      end
    }
  }
end