Module: Async::Container

Defined in:
lib/async/container.rb,
lib/async/container/best.rb,
lib/async/container/error.rb,
lib/async/container/group.rb,
lib/async/container/keyed.rb,
lib/async/container/forked.rb,
lib/async/container/hybrid.rb,
lib/async/container/notify.rb,
lib/async/container/thread.rb,
lib/async/container/channel.rb,
lib/async/container/generic.rb,
lib/async/container/process.rb,
lib/async/container/version.rb,
lib/async/container/threaded.rb,
lib/async/container/controller.rb,
lib/async/container/statistics.rb,
lib/async/container/notify/pipe.rb,
lib/async/container/notify/client.rb,
lib/async/container/notify/server.rb,
lib/async/container/notify/socket.rb,
lib/async/container/notify/console.rb

Defined Under Namespace

Modules: Notify Classes: Channel, Controller, Error, Forked, Generic, Group, Hangup, Hybrid, Keyed, Process, SetupError, Statistics, Terminate, Thread, Threaded

Constant Summary collapse

Interrupt =
::Interrupt
ASYNC_CONTAINER_PROCESSOR_COUNT =

An environment variable key to override processor_count.

'ASYNC_CONTAINER_PROCESSOR_COUNT'
VERSION =
"0.16.10"

Class Method Summary collapse

Class Method Details

.best_container_classObject

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.



38
39
40
41
42
43
44
# File 'lib/async/container/best.rb', line 38

def self.best_container_class
	if fork?
		return Forked
	else
		return Threaded
	end
end

.fork?Boolean

Whether the underlying process supports fork.

Returns:

  • (Boolean)


31
32
33
# File 'lib/async/container/best.rb', line 31

def self.fork?
	::Process.respond_to?(:fork) && ::Process.respond_to?(:setpgid)
end

.new(*arguments, **options) ⇒ Object

Create an instance of the best container class.



48
49
50
# File 'lib/async/container/best.rb', line 48

def self.new(*arguments, **options)
	best_container_class.new(*arguments, **options)
end

.processor_count(env = ENV) ⇒ Object

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.



39
40
41
42
43
44
45
46
47
48
49
# 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