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.
6 7 8 9 10 11 |
# File 'lib/restify/promise.rb', line 6 def initialize(*dependencies, &task) @task = task @dependencies = dependencies.flatten super(&nil) end |
Class Method Details
.create {|Writer.new(promise)| ... } ⇒ Object
52 53 54 55 56 |
# File 'lib/restify/promise.rb', line 52 def create promise = Promise.new yield Writer.new(promise) promise end |
.fulfilled(value) ⇒ Object
58 59 60 61 62 |
# File 'lib/restify/promise.rb', line 58 def fulfilled(value) create do |writer| writer.fulfill value end end |
.rejected(value) ⇒ Object
64 65 66 67 68 |
# File 'lib/restify/promise.rb', line 64 def rejected(value) create do |writer| writer.reject value end end |
Instance Method Details
#execute(timeout = nil) ⇒ Object
22 23 24 |
# File 'lib/restify/promise.rb', line 22 def execute(timeout = nil) synchronize { ns_execute timeout } end |
#then(&block) ⇒ Object
18 19 20 |
# File 'lib/restify/promise.rb', line 18 def then(&block) Promise.new([self], &block) end |
#wait(timeout = nil) ⇒ Object
13 14 15 16 |
# File 'lib/restify/promise.rb', line 13 def wait(timeout = nil) execute if pending? super end |