module IO::Event::Selector

def self.default(env = ENV)

@returns [Class] The default selector implementation.
@parameter env [Hash] The environment to read configuration from.

The default selector implementation, which is chosen based on the environment and available implementations.
def self.default(env = ENV)
	if name = env["IO_EVENT_SELECTOR"]&.to_sym
		return const_get(name)
	end
	
	if self.const_defined?(:URing)
		URing
	elsif self.const_defined?(:EPoll)
		EPoll
	elsif self.const_defined?(:KQueue)
		KQueue
	else
		Select
	end
end

def self.new(loop, env = ENV)

@returns [Selector] The new selector instance.
@parameter env [Hash] The environment to read configuration from.
@parameter loop [Fiber] The event loop fiber.

Create a new selector instance, according to the best available implementation.
def self.new(loop, env = ENV)
	selector = default(env).new(loop)
	
	if debug = env["IO_EVENT_DEBUG_SELECTOR"]
		selector = Debug::Selector.wrap(selector, env)
	end
	
	return selector
end

def self.nonblock(io, &block)

@yields {...} The block to execute.
@parameter io [IO] The IO object to operate on.

Execute the given block in non-blocking mode.
def self.nonblock(io, &block)
	io.nonblock(&block)
rescue Errno::EBADF
	# Windows.
	yield
end