Class: Luego::Future

Inherits:
Delegate show all
Defined in:
lib/luego/future.rb

Instance Method Summary collapse

Methods inherited from Delegate

#delegate!, #send, #undelegate!

Constructor Details

#initialize(thread = nil, &block) ⇒ Future

Returns a new instance of Future.



8
9
10
11
# File 'lib/luego/future.rb', line 8

def initialize(thread = nil, &block)
  @thread = thread || ::Thread.new(&block)
  @thread.run
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



13
14
15
16
# File 'lib/luego/future.rb', line 13

def method_missing(*args, &block)
  await!
  super
end

Instance Method Details

#await!Object



18
19
20
21
22
# File 'lib/luego/future.rb', line 18

def await!
  return @child unless @child.nil?

  @child = @thread.value
end

#delegating?Boolean Also known as: ready?

Returns:

  • (Boolean)


24
25
26
# File 'lib/luego/future.rb', line 24

def delegating?
  !@thread.alive?
end