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.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/restify/promise.rb', line 5 def initialize(*dependencies, &task) @task = task @dependencies = dependencies.flatten super(&nil) # When dependencies were passed in, but none are left after flattening, # then we don't have to wait for explicit dependencies or resolution # through a writer. complete true, [], nil if !@task && @dependencies.empty? && dependencies.any? end |
Class Method Details
.create {|Writer.new(promise)| ... } ⇒ Object
65 66 67 68 69 |
# File 'lib/restify/promise.rb', line 65 def create promise = Promise.new yield Writer.new(promise) promise end |
.fulfilled(value) ⇒ Object
71 72 73 74 75 |
# File 'lib/restify/promise.rb', line 71 def fulfilled(value) create do |writer| writer.fulfill value end end |
.rejected(value) ⇒ Object
77 78 79 80 81 |
# File 'lib/restify/promise.rb', line 77 def rejected(value) create do |writer| writer.reject value end end |