class Async::Reactor

def with_timeout(timeout, exception = TimeoutError)

Parameters:
  • duration (Numeric) -- The time in seconds, in which the task should
def with_timeout(timeout, exception = TimeoutError)
	fiber = Fiber.current
	
	timer = @timers.after(timeout) do
		if fiber.alive?
			error = exception.new("execution expired")
			fiber.resume error
		end
	end
	
	yield timer
ensure
	timer.cancel if timer
end