~singpolyma/em_fiberscheduler

6925054609beea46ff3649b97094eed4db63b0c4 — Stephen Paul Weber 4 months ago 56c6d72
Run when there is any EM work left
1 files changed, 10 insertions(+), 1 deletions(-)

M lib/em_fiberscheduler.rb
M lib/em_fiberscheduler.rb => lib/em_fiberscheduler.rb +10 -1
@@ 4,6 4,15 @@ require "eventmachine"
require "fiber"

module EventMachine
	def self.work_left?
		if @timers.empty? && @next_tick_queue.empty? && defers_finished?
			# DNS UDP socket never gets removed
			!@conns.empty? && @conns.values != [DNS::Resolver.socket]
		else
			true
		end
	end

	class FiberScheduler
		def initialize
			@count = 0


@@ 17,7 26,7 @@ module EventMachine

		def tick
			EM.next_tick do
				if @count.positive?
				if @count.positive? || EM.work_left?
					tick
				else
					EM.stop