module Circuitry::Concerns::Async

Attributes

async[R]

Public Class Methods

included(base) click to toggle source
# File lib/circuitry/concerns/async.rb, line 12
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

async=(value) click to toggle source
# File lib/circuitry/concerns/async.rb, line 30
def async=(value)
  value = case value
          when false, nil then false
          when true then self.class.default_async_strategy
          when *self.class.async_strategies then value
          else raise ArgumentError, async_value_error(value)
          end

  if value == :fork && !platform_supports_forking?
    raise NotSupportedError, 'Your platform does not support forking'
  end

  @async = value
end
async?() click to toggle source
# File lib/circuitry/concerns/async.rb, line 45
def async?
  ![nil, false].include?(async)
end
process_asynchronously(&block) click to toggle source
# File lib/circuitry/concerns/async.rb, line 26
def process_asynchronously(&block)
  send(:"process_via_#{async}", &block)
end

Private Instance Methods

async_value_error(value) click to toggle source
# File lib/circuitry/concerns/async.rb, line 51
def async_value_error(value)
  options = [true, false].concat(self.class.async_strategies).inspect
  "Invalid value `#{value.inspect}`, must be one of #{options}"
end
platform_supports_forking?() click to toggle source
# File lib/circuitry/concerns/async.rb, line 56
def platform_supports_forking?
  Process.respond_to?(:fork)
end
process_via_batch(&block) click to toggle source
# File lib/circuitry/concerns/async.rb, line 68
def process_via_batch(&block)
  Processors::Batcher.process(&block)
end
process_via_fork(&block) click to toggle source
# File lib/circuitry/concerns/async.rb, line 60
def process_via_fork(&block)
  Processors::Forker.process(&block)
end
process_via_thread(&block) click to toggle source
# File lib/circuitry/concerns/async.rb, line 64
def process_via_thread(&block)
  Processors::Threader.process(&block)
end