Class: Rbfs::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/rbfs/futures.rb

Instance Method Summary collapse

Constructor Details

#initialize(&callable) ⇒ Future

Returns a new instance of Future.



3
4
5
# File 'lib/rbfs/futures.rb', line 3

def initialize(&callable)
  @thread ||= ::Thread.new { callable.call }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



19
20
21
# File 'lib/rbfs/futures.rb', line 19

def method_missing(method, *args)
  value.send(method, *args)
end

Instance Method Details

#inspectObject



11
12
13
14
15
16
17
# File 'lib/rbfs/futures.rb', line 11

def inspect
  if @thread.alive?
    "#<Future running>"
  else
    value.inspect
  end
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rbfs/futures.rb', line 23

def respond_to_missing?(method, include_private = false)
  value.respond_to?(method, include_private)
end

#valueObject



7
8
9
# File 'lib/rbfs/futures.rb', line 7

def value
  @thread.value
end