Class: WebFetch::Promise
- Inherits:
-
Object
- Object
- WebFetch::Promise
- Defined in:
- lib/web_fetch/promise.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #custom ⇒ Object
- #error ⇒ Object
- #fetch(options = {}) ⇒ Object
-
#initialize(client, options = {}) ⇒ Promise
constructor
A new instance of Promise.
- #pending? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/web_fetch/promise.rb', line 5 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/web_fetch/promise.rb', line 5 def response @response end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
5 6 7 |
# File 'lib/web_fetch/promise.rb', line 5 def uid @uid end |
Instance Method Details
#complete? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/web_fetch/promise.rb', line 24 def complete? return false if @response.nil? @response.complete? end |
#custom ⇒ Object
20 21 22 |
# File 'lib/web_fetch/promise.rb', line 20 def custom request&.custom end |
#error ⇒ Object
40 41 42 43 44 |
# File 'lib/web_fetch/promise.rb', line 40 def error return nil unless complete? @response.error end |
#fetch(options = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/web_fetch/promise.rb', line 13 def fetch( = {}) return @response if complete? wait = .fetch(:wait, true) @response = @client.fetch(@uid, wait: wait) end |
#pending? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/web_fetch/promise.rb', line 30 def pending? return false if @response.nil? @response.pending? end |
#success? ⇒ Boolean
36 37 38 |
# File 'lib/web_fetch/promise.rb', line 36 def success? complete? && @response.success? end |