EventSourceIOEventSelector

module Selector

Nested

Definitions

def self.nonblock(io, &block)

Execute the given block in non-blocking mode.

Signature

parameter io IO

The IO object to operate on.

yields {...}

The block to execute.

Implementation

def self.nonblock(io, &block)
	io.nonblock(&block)
rescue Errno::EBADF
	# Windows.
	yield
end

def self.default(env = ENV)

The default selector implementation, which is chosen based on the environment and available implementations.

Signature

parameter env Hash

The environment to read configuration from.

returns Class

The default selector implementation.

Implementation

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)

Create a new selector instance, according to the best available implementation.

Signature

parameter loop Fiber

The event loop fiber.

parameter env Hash

The environment to read configuration from.

returns Selector

The new selector instance.

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