~singpolyma/em_fiberscheduler

f17337f22400c96a38c5a4c5653658d79a343d0d — Stephen Paul Weber 4 months ago 29c8e6b
Try timeout_after
1 files changed, 13 insertions(+), 0 deletions(-)

M lib/em-fiberscheduler.rb
M lib/em-fiberscheduler.rb => lib/em-fiberscheduler.rb +13 -0
@@ 110,6 110,19 @@ module EventMachine
			Fiber.yield
		end

		def timeout_after(duration, exception_class, *exception_arguments, &block)
			timer = nil
			fiber = Fiber.current
			EM.schedule do
				timer = EM.add_timer(duration) do
					fiber.raise(exception_class, *exception_arguments)
				end
			end
			block.call
		ensure
			EM.cancel_timer(timer) if timer
		end

		module WatchProcess
			attr_writer :fiber