Class: UU::OS::Lang::Future
- Inherits:
-
Object
- Object
- UU::OS::Lang::Future
- Defined in:
- uu_os_commons-1.5.0/lib/uu/os/lang/future.rb
Overview
Object which is returned as result of all asynchronous tasks.
Instance Method Summary (collapse)
-
- (Object) get(timeout = 30)
Returns result of asynchronous task.
-
- (Future) initialize(actor)
constructor
Creates new instance of future object.
Constructor Details
- (Future) initialize(actor)
Creates new instance of future object.
13 14 15 16 17 18 19 20 21 22 |
# File 'uu_os_commons-1.5.0/lib/uu/os/lang/future.rb', line 13 def initialize(actor) if actor.respond_to?(:get) @actor = actor elsif actor.nil? raise ArgumentError, 'cannot get result of asynchronous task without actor.' @actor = nil else raise TypeError, "cannot handle actor of type #{actor.class}" end end |
Instance Method Details
- (Object) get(timeout = 30)
Returns result of asynchronous task. This call is blocking (it waits until result is provided or timeout exceeded).
34 35 36 37 38 39 40 41 |
# File 'uu_os_commons-1.5.0/lib/uu/os/lang/future.rb', line 34 def get(timeout = 30) return nil if @actor.nil? timeout = 30 if timeout > 30 timeout = 0.1 if timeout <= 0 Timeout::timeout(timeout) do @actor.get end end |