~singpolyma/em_fiberscheduler

56c6d72a34405cd5f4ad207a5ae9b301af0620a4 — Stephen Paul Weber 4 months ago 29835d2
Refactor io_wait
1 files changed, 12 insertions(+), 10 deletions(-)

M lib/em_fiberscheduler.rb
M lib/em_fiberscheduler.rb => lib/em_fiberscheduler.rb +12 -10
@@ 73,13 73,7 @@ module EventMachine
				conn.events = events & ~IO::PRIORITY
				conn.notify_readable = (events & IO::READABLE).positive?
				conn.notify_writable = (events & IO::WRITABLE).positive?

				if timeout
					EM.add_timer(timeout) do
						conn.detach
						fiber.resume
					end
				end
				conn.timeout = timeout if timeout
			end
			Fiber.yield
		end


@@ 170,6 164,13 @@ module EventMachine
		module IOWait
			attr_writer :fiber, :events

			def timeout=(timeout)
				@timeout = EM.add_timer(timeout) {
					detach
					@fiber.resume
				}
			end

			def notify_readable
				return unless (@events & IO::READABLE).positive?



@@ 177,10 178,10 @@ module EventMachine
				check
			end

			def notify_writeable
				return unless (@events & IO::WRITEABLE).positive?
			def notify_writable
				return unless (@events & IO::WRITABLE).positive?

				@events &= ~IO::WRITEABLE
				@events &= ~IO::WRITABLE
				check
			end



@@ 188,6 189,7 @@ module EventMachine
				return unless @events.zero?

				EM.next_tick { @fiber.resume }
				EM.cancel_timer(@timeout) if @timeout
				detach
			end
		end