Class: Blodsband::Future

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(&block) ⇒ Future

Create a future that will run a block upon request.

Parameters:

  • block (block)

    the block to run when #get is called.



16
17
18
# File 'lib/blodsband/future.rb', line 16

def initialize(&block)
  @block = block
end

Instance Method Details

#getObject

Get the result from the asynchronous operation.

Returns:

  • (Object)

    whatever the block given in #initialize produced.



25
26
27
# File 'lib/blodsband/future.rb', line 25

def get
  @value ||= @block.call
end