Class: Routemaster::Responses::ResponsePromise

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/routemaster/responses/response_promise.rb

Defined Under Namespace

Modules: Pool

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Forwardable

_compile_method

Constructor Details

#initialize(&block) ⇒ ResponsePromise

The block is expected to return a Response



12
13
14
# File 'lib/routemaster/responses/response_promise.rb', line 12

def initialize(&block)
  @promise = Concurrent::Promise.execute(executor: Pool.current, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



32
33
34
# File 'lib/routemaster/responses/response_promise.rb', line 32

def method_missing(m, *args, &block)
  value.public_send(m, *args, &block)
end

Instance Attribute Details

#bodyHashie::Mash

Delegated to the block's return value.

Returns:

  • (Hashie::Mash)


27
# File 'lib/routemaster/responses/response_promise.rb', line 27

delegate %i(status headers body) => :value

#headersHash

Delegated to the block's return value.

Returns:

  • (Hash)


# File 'lib/routemaster/responses/response_promise.rb', line 20

#statusInteger

Delegated to the block's return value.

Returns:

  • (Integer)


# File 'lib/routemaster/responses/response_promise.rb', line 16

Instance Method Details

#valueObject



36
37
38
39
40
# File 'lib/routemaster/responses/response_promise.rb', line 36

def value
  @promise.value.tap do
    raise @promise.reason if @promise.rejected?
  end
end