Class: ThomasUtils::FutureWrapper
- Inherits:
-
Object
- Object
- ThomasUtils::FutureWrapper
- Extended by:
- Forwardable
- Defined in:
- lib/thomas_utils/future_wrapper.rb
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(future, &callback) ⇒ FutureWrapper
constructor
A new instance of FutureWrapper.
- #on_success ⇒ Object
Constructor Details
#initialize(future, &callback) ⇒ FutureWrapper
Returns a new instance of FutureWrapper.
8 9 10 11 |
# File 'lib/thomas_utils/future_wrapper.rb', line 8 def initialize(future, &callback) @future = future @callback = callback end |
Instance Method Details
#get ⇒ Object
13 14 15 |
# File 'lib/thomas_utils/future_wrapper.rb', line 13 def get @result ||= @callback.call(@future.get) end |
#on_success ⇒ Object
17 18 19 |
# File 'lib/thomas_utils/future_wrapper.rb', line 17 def on_success @future.on_success { |result| yield @callback.call(result) } end |