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.



231
232
233
234
# File 'lib/sequel/extensions/async_thread_pool.rb', line 231

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.



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

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.



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/sequel/extensions/async_thread_pool.rb', line 260

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)


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

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