Class: Blodsband::Future
- Inherits:
-
Object
- Object
- Blodsband::Future
- Defined in:
- lib/blodsband/future.rb
Overview
A class that encapsulates an asynchronous operation.
Used to avoid the callback carbonara usually produced when relying heavily on asynchronous code.
Instance Method Summary collapse
-
#get ⇒ Object
Get the result from the asynchronous operation.
-
#initialize(&block) ⇒ Future
constructor
Create a future that will run a block upon request.
Constructor Details
#initialize(&block) ⇒ Future
Create a future that will run a block upon request.
16 17 18 |
# File 'lib/blodsband/future.rb', line 16 def initialize(&block) @block = block end |
Instance Method Details
#get ⇒ Object
Get the result from the asynchronous operation.
25 26 27 |
# File 'lib/blodsband/future.rb', line 25 def get @value ||= @block.call end |