class Async::Scheduler

def run_once(timeout = nil)

@returns [Boolean] Whether there is more work to do.
@parameter timeout [Float | Nil] The maximum timeout, or if nil, indefinite.
Run one iteration of the event loop.
def run_once(timeout = nil)
	Kernel::raise "Running scheduler on non-blocking fiber!" unless Fiber.blocking?
	
	# If we are finished, we stop the task tree and exit:
	if self.finished?
		return false
	end
	
	interval = @timers.wait_interval
	
	# If there is no interval to wait (thus no timers), and no tasks, we could be done:
	if interval.nil?
		# Allow the user to specify a maximum interval if we would otherwise be sleeping indefinitely:
		interval = timeout
	elsif interval < 0
		# We have timers ready to fire, don't sleep in the selctor:
		interval = 0
	elsif timeout and interval > timeout
		interval = timeout
	end
	
	begin
		@selector.select(interval)
	rescue Errno::EINTR
		# Ignore.
	end
	
	@timers.fire
	
	# The reactor still has work to do:
	return true
end