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 || proc { |*args| args }
  @dependencies = dependencies.flatten

  super(&nil)
end

Class Method Details

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

Yields:



72
73
74
75
76
# File 'lib/restify/promise.rb', line 72

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

Instance Method Details

#executeObject



23
24
25
# File 'lib/restify/promise.rb', line 23

def execute
  synchronize { ns_execute }
end

#then(&block) ⇒ Object



19
20
21
# File 'lib/restify/promise.rb', line 19

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

#wait(timeout = nil) ⇒ Object



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

def wait(timeout = nil)
  if @dependencies.any? && pending?
    execute
  end

  super
end