Class: Dramatis::Future::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/dramatis/future/interface.rb

Overview

A Dramatis::Future::Interface object provides the ability to observe and access the semantics of a future. It is typically created via Dramatis.interface.

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Interface

:nodoc:



44
45
46
47
48
# File 'lib/dramatis/future/interface.rb', line 44

def initialize *args, &block #:nodoc:
  @future = args.shift
  @args = args
  @block = block
end

Instance Method Details

#ready?Boolean

call-seq:

ready? -> boolean

Returns true if the future may be evaluated without blocking. Returns false if the value is not yet available.

Once a future is ready it cannot become unready, so once ready? returns true, it will always be true and value access will never block.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/dramatis/future/interface.rb', line 38

def ready?
  @future.instance_eval do
    @continuation.ready?
  end
end

#valueObject

call-seq:

value -> object

Returns the native value of the future. If the value of the future is not yet available, the method blocks (with rpc gating semantics) until it is.

In many cases, this method is not necessary since the method_missing method on the future will catch most attempts to accesses the value. This method may be necessary in corner cases, for example when using conditionals, conversions, and metaprogramming.



23
24
25
26
27
# File 'lib/dramatis/future/interface.rb', line 23

def value
  @future.instance_eval do
    @continuation.value
  end
end