module Async::Container

Constants

ASYNC_CONTAINER_PROCESSOR_COUNT

An environment variable key to override {.processor_count}.

Interrupt
VERSION

Public Class Methods

best_container_class() click to toggle source

Determins the best container class based on the underlying Ruby implementation. Some platforms, including JRuby, don't support fork. Applications which just want a reasonable default can use this method. @returns [Class]

# File lib/async/container/best.rb, line 38
def self.best_container_class
        if fork?
                return Forked
        else
                return Threaded
        end
end
fork?() click to toggle source

Whether the underlying process supports fork. @returns [Boolean]

# File lib/async/container/best.rb, line 31
def self.fork?
        ::Process.respond_to?(:fork) && ::Process.respond_to?(:setpgid)
end
new(*arguments, **options) click to toggle source

Create an instance of the best container class. @returns [Generic] Typically an instance of either {Forked} or {Threaded} containers.

# File lib/async/container/best.rb, line 48
def self.new(*arguments, **options)
        best_container_class.new(*arguments, **options)
end
processor_count(env = ENV) click to toggle source

The processor count which may be used for the default number of container threads/processes. You can override the value provided by the system by specifying the `ASYNC_CONTAINER_PROCESSOR_COUNT` environment variable. @returns [Integer] The number of hardware processors which can run threads/processes simultaneously. @raises [RuntimeError] If the process count is invalid.

# File lib/async/container/generic.rb, line 39
def self.processor_count(env = ENV)
        count = env.fetch(ASYNC_CONTAINER_PROCESSOR_COUNT) do
                Etc.nprocessors rescue 1
        end.to_i
        
        if count < 1
                raise RuntimeError, "Invalid processor count #{count}!"
        end
        
        return count
end