Class: Restify::Promise

Inherits:
Concurrent::IVar
  • Object
show all
Defined in:
lib/restify/promise.rb

Defined Under Namespace

Classes: Writer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*dependencies, &task) ⇒ Promise

Returns a new instance of Promise.



4
5
6
7
8
9
# File 'lib/restify/promise.rb', line 4

def initialize(*dependencies, &task)
  @task         = task
  @dependencies = dependencies.flatten

  super(&nil)
end

Class Method Details

.create {|Writer.new(promise)| ... } ⇒ Object

Yields:



68
69
70
71
72
# File 'lib/restify/promise.rb', line 68

def create
  promise = Promise.new
  yield Writer.new(promise)
  promise
end

Instance Method Details

#execute(timeout = nil) ⇒ Object



35
36
37
# File 'lib/restify/promise.rb', line 35

def execute(timeout = nil)
  synchronize { ns_execute timeout }
end

#then(&block) ⇒ Object



31
32
33
# File 'lib/restify/promise.rb', line 31

def then(&block)
  Promise.new([self], &block)
end

#wait(timeout = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/restify/promise.rb', line 11

def wait(timeout = nil)
  execute if pending?

  # if defined?(EventMachine)
  #   if incomplete?
  #     fiber = Fiber.current

  #     self.add_observer do
  #       EventMachine.next_tick { fiber.resume }
  #     end

  #     Fiber.yield
  #   else
  #     self
  #   end
  # else
    super
  # end
end