class Async::Task

def initialize(reactor, parent = Task.current?)

Parameters:
  • parent (Async::Task) -- the parent task.
  • reactor (Async::Reactor) -- the reactor this task will run within.
def initialize(reactor, parent = Task.current?)
	super(parent || reactor)
	
	@reactor = reactor
	
	@status = :initialized
	@result = nil
	
	@finished = nil
	
	@fiber = Fiber.new do |*args|
		set!
		
		begin
			@result = yield(self, *args)
			@status = :complete
			# Async.logger.debug("Task #{self} completed normally.")
		rescue Stop
			@status = :stop
			# Async.logger.debug("Task #{self} stopped: #{$!}")
		rescue Exception => error
			@result = error
			@status = :failed
			# Async.logger.debug("Task #{self} failed: #{$!}")
			raise
		ensure
			# Async.logger.debug("Task #{self} closing: #{$!}")
			finish!
		end
	end
end