Class: Sequel::Database::AsyncThreadPool::BaseProxy

Inherits:
BasicObject
Defined in:
lib/sequel/extensions/async_thread_pool.rb

Overview

Base proxy object class for jobs processed by async threads and the returned result.

Direct Known Subclasses

PreemptableProxy, Proxy

Instance Method Summary collapse

Methods inherited from BasicObject

const_missing

Constructor Details

#initialize(&block) ⇒ BaseProxy

Store a block that returns the result when called.



238
239
240
241
# File 'lib/sequel/extensions/async_thread_pool.rb', line 238

def initialize(&block)
  ::Kernel.raise Error, "must provide block for an async job" unless block
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Pass all method calls to the returned result.



244
245
246
# File 'lib/sequel/extensions/async_thread_pool.rb', line 244

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

Instance Method Details

#__valueObject

Wait for the value to be loaded if it hasn’t already been loaded. If the code to load the return value raised an exception that was wrapped, reraise the exception.



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/sequel/extensions/async_thread_pool.rb', line 267

def __value
  unless defined?(@value)
    __get_value
  end

  if @value.is_a?(WrappedException)
    ::Kernel.raise @value
  end

  @value
end

#respond_to_missing?(*args) ⇒ Boolean

Delegate respond_to? calls to the returned result.

Returns:

  • (Boolean)


252
253
254
# File 'lib/sequel/extensions/async_thread_pool.rb', line 252

def respond_to_missing?(*args)
  __value.respond_to?(*args)
end