Class: Restify::Promise
- Inherits:
-
Concurrent::IVar
- Object
- Concurrent::IVar
- Restify::Promise
- Defined in:
- lib/restify/promise.rb
Defined Under Namespace
Classes: Writer
Class Method Summary collapse
Instance Method Summary collapse
- #execute(timeout = nil) ⇒ Object
-
#initialize(*dependencies, &task) ⇒ Promise
constructor
A new instance of Promise.
- #then(&block) ⇒ Object
- #wait(timeout = nil) ⇒ Object
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
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 |