Class: Viewing::ViewProxy
- Inherits:
-
Object
- Object
- Viewing::ViewProxy
- Defined in:
- lib/view_proxy.rb
Overview
ViewProxy class threading proxy
Instance Method Summary collapse
-
#close ⇒ Object
close call.
-
#initialize(obj) ⇒ ViewProxy
constructor
initialization.
-
#store(key, values, options) ⇒ Object
thread-safe store call.
-
#update(name = nil) ⇒ Object
update loop.
Constructor Details
#initialize(obj) ⇒ ViewProxy
initialization
18 19 20 21 22 23 |
# 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 |
Instance Method Details
#close ⇒ Object
close call
64 65 66 67 68 |
# 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) ⇒ Object
thread-safe store call
30 31 32 33 34 35 |
# File 'lib/view_proxy.rb', line 30 def store(key,values,) @upd_mon.synchronize { @obj.store(key,values,) if @obj.respond_to?('store') @update.signal } end |
#update(name = nil) ⇒ Object
update loop
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 |