Sha256: 8f7cba80f94c15fc8217c1716bc661c4ad726ed48276cd25ea19deec13e54aee

Contents?: true

Size: 973 Bytes

Versions: 7

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2022, by Samuel Williams.

require_relative 'forked'
require_relative 'threaded'
require_relative 'hybrid'

module Async
	module Container
		# Whether the underlying process supports fork.
		# @returns [Boolean]
		def self.fork?
			::Process.respond_to?(:fork) && ::Process.respond_to?(:setpgid)
		end
		
		# 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]
		def self.best_container_class
			if fork?
				return Forked
			else
				return Threaded
			end
		end
		
		# Create an instance of the best container class.
		# @returns [Generic] Typically an instance of either {Forked} or {Threaded} containers.
		def self.new(*arguments, **options)
			best_container_class.new(*arguments, **options)
		end
	end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
async-container-0.18.3 lib/async/container/best.rb
async-container-0.18.2 lib/async/container/best.rb
async-container-0.18.1 lib/async/container/best.rb
async-container-0.18.0 lib/async/container/best.rb
async-container-0.17.1 lib/async/container/best.rb
async-container-0.17.0 lib/async/container/best.rb
async-container-0.16.13 lib/async/container/best.rb