Class: LazyMethods::AsyncProxy
Overview
:nodoc:
Constant Summary
Constants inherited from Proxy
Instance Method Summary collapse
- #__proxy_loaded__ ⇒ Object
-
#__proxy_result__ ⇒ Object
Get the result of the original method call.
-
#initialize(&block) ⇒ AsyncProxy
constructor
A new instance of AsyncProxy.
Methods inherited from Proxy
Constructor Details
#initialize(&block) ⇒ AsyncProxy
Returns a new instance of AsyncProxy.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/lazy_methods.rb', line 113 def initialize(&block) @proxy_result = nil @proxy_exception = nil if defined?(Thread.critical) && Thread.critical @proxy_result = block.call else @thread = Thread.new do begin @proxy_result = block.call rescue Exception => e @proxy_exception = e end end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class LazyMethods::Proxy
Instance Method Details
#__proxy_loaded__ ⇒ Object
137 138 139 |
# File 'lib/lazy_methods.rb', line 137 def __proxy_loaded__ !(@thread && @thread.alive?) end |
#__proxy_result__ ⇒ Object
Get the result of the original method call. The original method will only be called once.
130 131 132 133 134 135 |
# File 'lib/lazy_methods.rb', line 130 def __proxy_result__ @thread.join if @thread && @thread.alive? @thread = nil raise @proxy_exception if @proxy_exception return @proxy_result end |