Class: Fear::Promise Private
- Inherits:
-
Concurrent::IVar
- Object
- Concurrent::IVar
- Fear::Promise
- Defined in:
- lib/fear/promise.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#complete(result) ⇒ Boolean
private
Complete this promise with result.
-
#complete!(result) ⇒ self
private
Complete this promise with result.
- #completed? ⇒ Boolean private
-
#failure(error) ⇒ Boolean
private
Complete this promise with failure.
-
#failure!(error) ⇒ self
private
Complete this promise with failure.
-
#initialize(options = {}) ⇒ Promise
constructor
private
A new instance of Promise.
-
#success(value) ⇒ Boolean
private
Complete this promise with successful result.
-
#success!(value) ⇒ self
private
Complete this promise with failure.
- #to_future ⇒ Fear::Future private
Constructor Details
#initialize(options = {}) ⇒ Promise
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Promise.
5 6 7 8 9 10 11 |
# File 'lib/fear/promise.rb', line 5 def initialize( = {}) super() @options = @promise = Concurrent::Promise.new() do Fear.try { value }.flatten end end |
Instance Method Details
#complete(result) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Complete this promise with result
77 78 79 80 81 82 83 84 85 |
# File 'lib/fear/promise.rb', line 77 def complete(result) if completed? false else set result promise.execute true end end |
#complete!(result) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Complete this promise with result
63 64 65 66 67 68 69 |
# File 'lib/fear/promise.rb', line 63 def complete!(result) if complete(result) self else raise IllegalStateException, 'Promise already completed.' end end |
#completed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/fear/promise.rb', line 16 def completed? complete? end |
#failure(error) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Complete this promise with failure
46 47 48 |
# File 'lib/fear/promise.rb', line 46 def failure(error) complete(Fear.failure(error)) end |
#failure!(error) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Complete this promise with failure
55 56 57 |
# File 'lib/fear/promise.rb', line 55 def failure!(error) complete!(Fear.failure(error)) end |
#success(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Complete this promise with successful result
29 30 31 |
# File 'lib/fear/promise.rb', line 29 def success(value) complete(Fear.success(value)) end |
#success!(value) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Complete this promise with failure
38 39 40 |
# File 'lib/fear/promise.rb', line 38 def success!(value) complete!(Fear.success(value)) end |
#to_future ⇒ Fear::Future
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/fear/promise.rb', line 21 def to_future Future.new(promise, ) end |