class Async::Task

def initialize(ios, reactor)

Returns:
  • (void) -

Parameters:
  • reactor (Async::Reactor) --
  • ios (Array) -- an array of `IO` objects such as `TCPServer`, `Socket`, etc.
def initialize(ios, reactor)
	if parent = Task.current?
		super(parent)
	else
		super(reactor)
	end
	
	@ios = Hash[
		ios.collect{|io| [io.fileno, reactor.wrap(io, self)]}
	]
	
	@reactor = reactor
	
	@status = :running
	@result = nil
	
	@condition = nil
	
	@fiber = Fiber.new do
		set!
		
		begin
			@result = yield(*@ios.values, self)
			@status = :complete
			# Async.logger.debug("Task #{self} completed normally.")
		rescue Interrupt
			@status = :interrupted
			# Async.logger.debug("Task #{self} interrupted: #{$!}")
		rescue Exception => error
			@result = error
			@status = :failed
			# Async.logger.debug("Task #{self} failed: #{$!}")
			raise
		ensure
			# Async.logger.debug("Task #{self} closing: #{$!}")
			close
		end
	end
end