Class: Dispatch::Future

Inherits:
Promise show all
Defined in:
lib/futuristic/dispatch/future.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dispatch::Promise

Class Method Details

.new(&block) ⇒ Object

Create s new Future

Example:

>> future = Dispatch::Future.new { long_taking_task; 10 }
=> future.value # 10

Arguments

block, last


13
14
15
16
17
18
19
20
# File 'lib/futuristic/dispatch/future.rb', line 13

def self.new(&block)
  # MacRuby and Rubymotion BasicObject#initialize doesn't like blocks, so we have to do this
  # new :: a -> Eval (Future a)
  unless block_given?
    ::Kernel.raise(::ArgumentError, "You cannot initalize a Dispatch::Future without a block")
  end
  self.alloc.initialization(block)
end

Instance Method Details

#descriptionObject Also known as: to_s, inspect

Future#description

> <Future: 0x400d382a0 run>



39
40
41
42
# File 'lib/futuristic/dispatch/future.rb', line 39

def description
  state = done? ? :dead : :run
  NSString.stringWithString(super.gsub(/>/, " #{state}>"))
end

#done?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/futuristic/dispatch/future.rb', line 47

def done?
  !!@value
end

#initialization(block) ⇒ Object



29
30
31
32
33
# File 'lib/futuristic/dispatch/future.rb', line 29

def initialization(block)
  super(block)
  __force__
  self
end

#valueObject



52
53
54
# File 'lib/futuristic/dispatch/future.rb', line 52

def value
  __value__
end

#when_done(&call_back) ⇒ Object



23
24
25
26
# File 'lib/futuristic/dispatch/future.rb', line 23

def when_done(&call_back)
  @group.notify(@promise_queue) { call_back.call __value__ }
  self
end