Class: EventMachine::Q::ResolvedPromise
- Defined in:
- lib/em-promise/q.rb
Instance Method Summary collapse
-
#initialize(response, error = false) ⇒ ResolvedPromise
constructor
A new instance of ResolvedPromise.
- #then(callback = nil, errback = nil, &blk) ⇒ Object
Constructor Details
#initialize(response, error = false) ⇒ ResolvedPromise
Returns a new instance of ResolvedPromise.
95 96 97 98 99 100 101 |
# File 'lib/em-promise/q.rb', line 95 def initialize(response, error = false) raise ArgumentError if error && response.is_a?(Promise) super() @error = error @response = response end |
Instance Method Details
#then(callback = nil, errback = nil, &blk) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/em-promise/q.rb', line 103 def then(callback = nil, errback = nil, &blk) result = Q.defer callback ||= blk EM.next_tick { if @error result.resolve(errback.nil? ? Q.reject(@response) : errback.call(@response)) else result.resolve(callback.nil? ? @response : callback.call(@response)) end } result.promise end |